Apr 12, 2005 #1 LuckyKoen Programmer Feb 14, 2005 57 BE I have $string that contains "1.2.3" I would like to get the . out but with $string =~ s/./_/g the numbers are also replaced with _ instead of only the dots. How do I make sure that only the dots are replaced and not every character in $string ?
I have $string that contains "1.2.3" I would like to get the . out but with $string =~ s/./_/g the numbers are also replaced with _ instead of only the dots. How do I make sure that only the dots are replaced and not every character in $string ?
Apr 12, 2005 #2 rharsh Technical User Apr 2, 2004 960 US For regexs, '.' means any single character, but if you escape it ('\.') it's a literal period. Try: Code: $string =~ s/\./_/g; Upvote 0 Downvote
For regexs, '.' means any single character, but if you escape it ('\.') it's a literal period. Try: Code: $string =~ s/\./_/g;
Apr 12, 2005 #3 RMGBELGIUM MIS Jul 28, 2004 726 BE try this one $string =~ s/\./_/g; greetz, R. Upvote 0 Downvote
Apr 12, 2005 Thread starter #4 LuckyKoen Programmer Feb 14, 2005 57 BE This works, thanks Upvote 0 Downvote
Apr 12, 2005 #5 ishnid Programmer Aug 29, 2003 1,422 IE Since it's single-character replacement you need, it's possibly better with a straight transliteration, rather than a regexp: Code: $string =~ tr/./_/; Don't let looks deceive you - it's not a regexp - hence why I haven't escaped the dot, as it has no special meaning. Upvote 0 Downvote
Since it's single-character replacement you need, it's possibly better with a straight transliteration, rather than a regexp: Code: $string =~ tr/./_/; Don't let looks deceive you - it's not a regexp - hence why I haven't escaped the dot, as it has no special meaning.