in reply to Word boundaries
Where to use \b and \B in Regular expression? I'm a beginner to Pearl. So, I didn't get clear understanding.It looks like the question changed since Anonymous Monk commented, so I'll archive what I'm answering. Please note that PM likes to archive threads as they were for posterity. Next time you have a new question, please start a new thread.
\b and \B are documented in Assertions in perlre. It is also discussed in perlretut, saying:
An anchor useful in basic regexps is the word anchor \b. This matches a boundary between a word character and a non-word character \w\W or \W\w:Note in the last example, the end of the string is considered a word boundary.$x = "Housecat catenates house and cat"; $x =~ /cat/; # matches cat in 'housecat' $x =~ /\bcat/; # matches cat in 'catenates' $x =~ /cat\b/; # matches cat in 'housecat' $x =~ /\bcat\b/; # matches 'cat' at end of string
In general, the most useful skill you can develop early in learning about Perl is navigating the documentation.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|