July 18th, 2013, 01:49 PM
Regex for replacing the first word of a string from - to _
below is my string and I am using to convert variable theline first word with - to _.
$theline =~ s/-^/_/g;
my $theline = Real-Blockset ("70" , "Aerospace Blockset" , " Aerospace_Blockset", "AE", "aeroblks"),
real_Toolbox ("108" , "Aerospace Toolbox" , " Aerospace_Toolbox", "AT", "aero"),
but my above regex is not changing the - to _.
Please help !!!
July 19th, 2013, 01:16 AM
Remove the circumflex accent (^) from the regex.
The ^ assertion means start of string (or start of line in some specific contexts). Therefore /-^/ cannot match anything.
$theline =~ s/-/_/g;
Comments on this post
July 19th, 2013, 12:16 PM
If it should be only in the first word, something like this:
I had not seen that part of the requirement and did not have time to come back until now.
$theline =~ s/^(\d+)-/$1_/g;