我想转动这个字符串;
0000,0767,"078", 0785, "0723",23487, 345 , 07334
进入此字符串;
"0000","0767","078", "0785", "0723","23487", "345" , "07334"
这是我能得到的最接近的,我总是对负面查找感到困惑,这就像正则表达式一样。
[^"\d,]?(\d+)
并替换为"$1"
- https://regex101.com/r/qVQYA7/1
不幸的是,这导致整数的双重引号已经有了双引号,就像这样;
"0000","0767",""078"","0785", ""0723"","23487","345" ,"07334"
伪逻辑是; 查找不已经有双引号的整数,并添加双引号。在逗号之间保留任何间距。
答案 0 :(得分:2)
您只需搜索"?(\d+)"?
并将其替换为"$1"
即可。
如果有"目前,他们匹配但不包含在小组中。
答案 1 :(得分:1)
您可以在正则表达式中使用外观来避免匹配引用的数字:
(?<!")(\b\d+\b)(?!")
RegEx分手:
(?<!") # Negative lookbehind to skip the match if previous character is "
( # captured group #1 open
\b # assert word boundary
\d+ # match 1 or more digits
\b # assert word boundary
) # captured group close
(?!") # Negative lookahead to skip the match if next character is "
如果你正在使用PCRE,那么你可以使用这个PCRE动词:
"\d+"(*SKIP)(*F)|(\d+)
答案 2 :(得分:1)