任何人都可以在Regular Expression
中解释下面Perl
模式的含义吗?
s/^(-?\d+)(\d\d\d)/$1,$2/
答案 0 :(得分:0)
取字符串:
-1234567890
使用正则表达式模式:
s/^(-?\d+)(\d\d\d)/$1,$2/
| | | | | | | |
| | | | \|/ replace pattern using groups [1],[2]
| | | | [2] match a digit [0-9] (3 times)
| | | [1] match a digit between one and unlimited times
| |[1] matches character "-" literally between zero and one time [greedy]
| ^ assert position at start of the string
substitution pattern
使用上面的原始字符串将变为:
-1234567,890
示例: