如果以下两种情况都是真的,我希望用,替换为.:
,应该只在字符串中出现一次。,后面最多应为两位数这些都没问题:1 000 000,51,1.000,9
这些不是:9,523,036.11,1,000
到目前为止我的进化:https://regex101.com/r/njuKtb/1
发布于 2018-09-27 14:58:13
您可以使用此正则表达式进行搜索:
^([^,]*),(?=\d{1,2}(?!\d))(?!.*,)并使用此替换:
$1.RegEx详细信息:
^([^,]*):在开头匹配0或多个非逗号字符。,:匹配文字逗号(?=\d{1,2}(?!\d)):匹配1或2位数,后面没有另一位数字(?!.*,):确保前面没有逗号另一种方法是将其用于搜索:
^([^,]*),(?=\d{1,2}(?!\d))([^,\n]*)$并以下列案文取代:
$1.$2发布于 2018-09-27 15:12:43
你可以:
/^(?!^[^,\n]*,[^,\n]*,[^,\n]*)(?:[^,\n]*),(?=\d{1,2}\D*$)/m即:
^ Start of string or line
(?!^[^,\n]*,[^,\n]*,[^,\n]*) Only matches lines with a single ','
(?:[^,\n]*) Suck up the LH before the ,
, The ,
(?=\d{1,2}\D*$) no more than two \d before end of the line https://stackoverflow.com/questions/52539784
复制相似问题