PDA

View Full Version : Perl & RE help (matching lines beginning with spaces...)



enigma_0Z
October 14th, 2006, 04:38 PM
I'm writing a script in perl, but for some reason it doesn't seem to be matching spaces at the beginning of lines... here's the RE I'm using (I just want to match 1 or more spaces at the beginning of lines and delete them)

s/^ +//g

That is right, isn't it? Thanks.

Houman
October 14th, 2006, 05:41 PM
Hi there,
to specify whitespaces you have to use \s, try this:

s/^\s+//g;

although this will remove all whitespaces
also if your string is multiline (you slurped the text for example) I think you gotta use the m modifier as well as g (i think):

s/^\s+//gm;

regards

Houman