我希望匹配任何文本中的某些行,并在该匹配内,将某个字符替换为它出现的次数一样多。
示例文本:
Any text and "much" "more" of it. Don't replace quotes here
CatchThis( no quotes here, "any more text" , "and so on and so forth...")
catchthat("some other text" , "or less")
some text in "between"
CatchAnything ( "even more" , "and more", no quotes there, "wall of text")
more ("text"""") and quotes after...
现在,我想要用另一个符号(比如 #)来替换括号内部的每个引号。
期望的输出:
Any text and "much" "more" of it. Don't replace quotes here
CatchThis( no quotes here, #any more text# , #and so on and so forth...#)
catchthat(#some other text# , #or less#)
some text in "between"
CatchAnything ( #even more# , #and more#, no quotes there, #wall of text# )
more ("text"""") and quotes after...
匹配这些行很容易。这是我的模式:
(?i)Catch(?:This|That|Anything)[ \t]*\(.+\)
很遗憾,我不知道如何匹配每一个引号并替换它...
[^()"]*
)。 - Wiktor Stribiżew