Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: match whitespace or beginning/end of string

by ikegami (Patriarch)
on Nov 02, 2009 at 15:36 UTC ( [id://804474]=note: print w/replies, xml ) Need Help??


in reply to Re^2: match whitespace or beginning/end of string
in thread match whitespace or beginning/end of string

\b and \s don't work if the substring to be matched comes at the beginning of the string.

If you're going to contradict, please test first. You would have found yourself wrong. The beginning and the end of the string count as whitespace for \b. This is documented and observable:

$_ = 'alpha="first" beta="second" gamma="third"'; for my $id (qw( alpha beta gamma )) { my ($val) = /\b$id=("[^"]*"|\w+)/ or next; print("$id: $val\n"); }
alpha: "first" beta: "second" gamma: "third"

Or

$_ = 'alpha="first" beta="second" gamma="third"'; while (/(\w+)=("[^"]*"|\w+)/g) { print("$1: $2\n"); }
alpha: "first" beta: "second" gamma: "third"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://804474]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-25 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found