Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: how to deal with newline

by Laurent_R (Parson)
on Oct 27, 2013 at 16:55 UTC ( #1059923=note: print w/ replies, xml ) Need Help??


in reply to how to deal with newline

Besides the line by line issue already identified, one of the problems with your regex is greedy match. If your line contains something like this:

'some random text..name="Bob"..some more random text surname="Dylan" some more text'

the name=\"(.*)\" part of your regex will match as much as it can between quotes, i.e.:

Bob"..some more random text surname="Dylan

You have to either make your * quantifier non greedy by adding the ? qualifier, name=\"(.+?)\", or match characters which are anything but quotes, name=\"([^"]+)\" (I also changed * to + because it does not seem to make too much sense to match an empty string between quotes).


Comment on Re: how to deal with newline
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-11-24 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (137 votes), past polls