我正在尝试创建一个PCRE RegEx,包围包含带有引号(")的字符串;@tab;@tab;@tab;的字符串。输入由多行文本组成,其中包含用选项卡分隔的一个或多个列。必须用引号(")包围的字符串可以位于行的乞求处、行的末尾或行的中间。行可以包含必须被包围的0或更多字符串。
示例:
1 some text with spaces
1 some text with spaces anotherValue
1 some text with spaces anotherValue 3452.2
val_so some text with spaces anotherValue 3452.2
val_so space some text with spaces anotherValue 3452.2
some text with spaces anotherValue 3 other text with spaces
1 some;t@b;t@b;t@b;text;t@b;t@b;t@b;with tabs
1 some;t@b;t@b;t@b;text;t@b;t@b;t@b;with tabs and spaces anotherValue
1 some;t@b;t@b;t@b;text;t@b;t@b;t@b;with spaces anotherValue 3452.2
val_so some;t@b;t@b;t@b;text with spaces and;t@b;t@b;t@b; tabs anotherValue 3452.2
val_so space some text with;t@b;t@b;t@b; spaces amd tabs anotherValue 3452.2
some text;t@b;t@b;t@b; with spaces anotherValue 3 other text;t@b;t@b;t@b;with spaces;t@b;t@b;t@b;and tabs
;t@b;t@b;t@b; with spaces anotherValue 3 other text;t@b;t@b;t@b;with spaces;t@b;t@b;t@b;and tabs
;t@b;t@b;t@b;;t@b;t@b;t@b; with spaces anotherValue 3 other text;t@b;t@b;t@b;with spaces;t@b;t@b;t@b;and tabs必须成为
1 some text with spaces
1 some text with spaces anotherValue
1 some text with spaces anotherValue 3452.2
val_so some text with spaces anotherValue 3452.2
val_so space some text with spaces anotherValue 3452.2
some text with spaces anotherValue 3 other text with spaces
1 "some;t@b;t@b;t@b;text;t@b;t@b;t@b;with tabs"
1 "some;t@b;t@b;t@b;text;t@b;t@b;t@b;with tabs and spaces" anotherValue
1 "some;t@b;t@b;t@b;text;t@b;t@b;t@b;with spaces" anotherValue 3452.2
val_so "some;t@b;t@b;t@b;text with spaces and;t@b;t@b;t@b; tabs" anotherValue 3452.2
val_so space "some text with;t@b;t@b;t@b; spaces amd tabs" anotherValue 3452.2
"some text;t@b;t@b;t@b; with spaces" anotherValue 3 "other text;t@b;t@b;t@b;with spaces;t@b;t@b;t@b;and tabs"
";t@b;t@b;t@b; with spaces" anotherValue 3 "other text;t@b;t@b;t@b;with spaces;t@b;t@b;t@b;and tabs"
";t@b;t@b;t@b;;t@b;t@b;t@b; with spaces" anotherValue 3 "other text;t@b;t@b;t@b;with spaces;t@b;t@b;t@b;and tabs"我尝试了以下PCRE RegEx搜索RegEx:带有g标志的\b(([^\t]+);t@b;([^\t]+))\b替换RegEx:"\2",但是它匹配跨多行的字符串(匹配不停止在行的末尾),但我希望每一行都分别匹配。
发布于 2020-10-22 21:46:24
由于数据是由制表符分隔的,而且您不想跨换行符,所以可以通过在否定式字符类中添加换行符来排除它们的匹配。
您可以省略单词边界,例如,它将与;在;t@b;t@b;t@b;的开头和结尾不匹配。
您不需要捕获组,因为您希望在双引号之间替换整个匹配。
[^\t\r\n]+;t@b;[^\t\r\n]+在替换中,使用双引号之间的整个匹配。
"$0"https://stackoverflow.com/questions/64490533
复制相似问题