Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: Help with placing the matches of a regex into an Array

by stevieb (Monsignor)
on Apr 28, 2012 at 20:39 UTC ( #967860=note: print w/replies, xml ) Need Help??

in reply to Re: Help with placing the matches of a regex into an Array
in thread Help with placing the matches of a regex into an Array

ahhhh, of course. Thanks JavaFan. In my example above, the /g isn't needed due to the fact I was reading a line at a time, but kept it in as I (correctly) assumed the OP would have multiple links in a scalar glob. Since I didn't test it as such though, I missed this bug.

I'm far from an expert in regexes, so I'm wondering if using the non-greedy operator essentially does the same thing in this case... or is there possibly something else I am missing that you see?


Replies are listed 'Best First'.
Re^3: Help with placing the matches of a regex into an Array
by JavaFan (Canon) on Apr 28, 2012 at 20:47 UTC
    It depends on the data -- if the data is incorrectly formatted (a missing ' for instance), they may not do the same thing. And '.+?' has the tendency to be slower than '[^']+'. Usually, the more restrictive a pattern is, the faster: there's less opportunity to backtrack. There's much more commitment in '[^']+' then there is in '.+?': the former will always match two quotes in succession, and whatever is in between, regardless how the rest of the pattern looks like, but that's not the case with '.+?'; there's nothing stopping the .+? part to match quotes.

      Thank you for your explanation. I'm still working on bettering my understanding of the look-ahead/backtrack aspects when working with Perl regexs. You've made it very clear to me here with this example.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://967860]
[Corion]: marto: Ooof - but yes, being there as only second level support or third level support is good and if you have enough things that you can work on, it won't be a wasted (if paid) day
[marto]: I've opted for a day off later on, rather than pay. I only have to do about 45 mins work for the client, but do need to hang around
[Corion]: marto: Even better ;)
[marto]: and I'm off next week1
[Corion]: Whee! ;)
[Corion]: I was away last week already, so I know how good a week off is ;))

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-02-28 10:08 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (399 votes). Check out past polls.