Can anyone explain the meaning of the Regular Expression
pattern below in Perl
?
s/^(-?\d+)(\d\d\d)/$1,$2/
Take the string:
-1234567890
Using the regex pattern:
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
Using the original string above would become:
-1234567,890
Example:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments