Please do pardon me if my question sounds a bit awkward. I am looking for a regex which will replace line numbers in perl source file without affecting values assigned to scalars.
I think below will make my question a little bit clearer. Say I have a perl source which looks like this:
1. $foo = 2.4;
2. print $foo;
I would like a regular expression to replace those line numbers (1. 2. etc..) without affecting value assigned to scalars, and so in this case $foo.
Thanks
Within a perl regex you can use the caret symbol
^to represent the start of a line.$represents the end of a line. These are known as anchors.So to find a number
\dat the beginning of a line (only) you can search forIf you wanted to remove those numbers you can “replace” them with nothing, as in
You also want to include the dot after the number, so you might try
;
But in regex a dot represents “any character” so you will need to escape the dot to have it interpreted literally
The caret symbol
^also serves double-duty in character sets (it negates them), I only mention this as it is a common source of confusion when learning regex.