Not quite right, parenthesis have special meaning in Perl regular expressions. Also \d{4} means any 4 digits while d{4} means dddd. And the "|" has no special meaning in the substitution part of the expression The Learning Perl book has great chapters on this. It's also a great reference for those new to Perl. So here's how all your examples could have been written. s/nxny \d{4} 5041/nxny 5041/g; # nxny followed by 4 digits then 5041 replace by nxny 5041 s/nx \d{4}/nx 71/g; # nx followed by 4 digits replace by nx 71 s/ny 1/ny 71/g; # ny 1 replace by nx 71 ny 71 s/\(\d{4} x 1\)/(71 x 71)/g; # (4 digits x 1) in brackets replace by (71 x 71)
In the future, you might want to give an example source text with expected results to make it clearer what you are trying to do. All the above regular expressions require each section to be separated by a single space. Also the 3rd one may not be quite right either depending on your data. Since it would replace "nxny 1234" with "nxny 71234" This is what I mean about knowing your data. Curtis ________________________________ From: activeperl-boun...@listserv.activestate.com [mailto:activeperl-boun...@listserv.activestate.com] On Behalf Of zilore mumba Sent: Friday, August 21, 2009 10:04 AM To: activeperl@listserv.activestate.com Subject: help rewrite files Further to my earlier mail, this is how I have constructed my search/replace patterns s/nxny d{4} 5041/nxny 5041/g; # nxny followed by 4 digits then 5041 replace by nxny 5041 s/(nx d{4}|ny 1)/nx 71|ny 71/g; # nx followed by 4 digits & ny 1 replace by nx 71 ny 71 s/(d{4} x 1)/(71 x 71)/g; # (4 digits x 1) in brackets replace by (71 x 71) I wonder if the search/replace syntax is correct Thanks for help Zilore
_______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs