in reply to multi line matching problem
Better still, if you want to replace all the greater than one space(s) in your regular expression and take care of any newlines that you have at the time, you can do so with this RegEx:$data =~ y/\n/ /; # This will remove all newlines and replace them wit +h spaces
The main key here is that \s* has been replaced with \s+, so it's no longer greedy and will replace only multiple space characters.$data =~ s/\s+|\n/ /g;
The difference between s and m is that s is used to substitue an expression, whilst m is used to test for a pattern match. M is not really used too much as it is implied when you place a regular expression between two slashes (ie. $data =~ /\n/g is the same as $data=~ m/\n/g). The y modifier is a simple character replacement (transliteration).
Update: With much thanks to Enlil for the explaination, the whole regex could actually be written without the \n (i.e. $data =~ s/\s+/ /g).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: multi line matching problem
by welchavw (Pilgrim) on Dec 16, 2003 at 02:50 UTC | |
by SquireJames (Monk) on Dec 16, 2003 at 02:57 UTC | |
by welchavw (Pilgrim) on Dec 16, 2003 at 03:15 UTC | |
by SquireJames (Monk) on Dec 16, 2003 at 03:26 UTC | |
by Roger (Parson) on Dec 16, 2003 at 04:08 UTC | |
Re: Re: multi line matching problem
by jcpunk (Friar) on Dec 16, 2003 at 02:47 UTC |
In Section
Seekers of Perl Wisdom