所以我认为我知道一点正则表达式,但似乎我发现了一个 case ,我的知识到了尽头. 不管怎么说,我试了以下Regex Replace function: in cases of no match, $1 returns full line instead of null种 但主要的区别是,我不仅希望用匹配替换输入,还希望在匹配之间插入一些字符.简单地说,我想将输入标准化为特定的模式. 我希望匹配和捕获输入的特定部分的正则表达式,但不是全部
^[\D]*(?P<from_day>(0?[1-9])|([12][0-9])|3[01])[\.\-\s,■]+(?P<from_month>(0?[1-9])|(1[0-2]))[\.\-\s,■]*(?P<until_day>(0?[1-9])|[12][0-9]|3[01])[\.\-\s,■]+(?P<until_month>(0?[1-9])|1[012])[\D]*$
替换字符串:
\g<from_day>.\g<from_month>-\g<until_day>.\g<until_month>
输入:
28.11 16.12
"13.01 23,09"
01.08.-31.12
"01.01,-51.12"
"01,01.-31,12."
01083112
1.02 - 4.3
当前输出:
28.11-16.12.-.
13.01-23.09.-.
01.08-31.12.-.
.-..-.
01.01-31.12.-.
.-..-.
1.02-4.3.-.
预期/所需:
28.11-16.12
13.01-23.09
01.08-31.12
01.01-31.12
1.02-4.3