Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: disregard spaces while matching ?

by hmerrill (Friar)
on Aug 05, 2004 at 12:05 UTC ( [id://380233] : note . print w/replies, xml ) Need Help??


in reply to Re: disregard spaces while matching ?
in thread disregard spaces while matching ?

No need to surround the \s+ with parenthesis. The only reason to use parenthesis is if you want to "capture" that part of the match. Using your example:
if( $test_string =~ /hello(\s+)world/ig ) { $spaces_between = $1; ### $1 comes from matching the ### expression in parenthesis $ct_spaces_between = length $spaces_between; print "FOUND IT! The number of spaces between 'hello' and 'world +' was $ct_spaces_between\n"; }
You should be able to use just /hello\s+world/ as your regular expression.

HTH.