Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Crafting a regex

by ahunter (Monk)
on Oct 11, 2000 at 21:29 UTC ( #36262=note: print w/replies, xml ) Need Help??

in reply to Crafting a regex

Perl is fairly good at compiling regexps, and provided you only use the constructs that can be simulated with a 'standard' regexp (which is to say, provided you can construct a deterministic finite automata from the expression), the running time should be O(n), where n is the length of the string being matched against.

This means you should avoid using anything that might cause perl to backtrack or lookahead - mostly that means the (?...) operators.

Anyhow, from your example, it looks like the closing quote is always the last one, so you could just take advantage of perl's greediness and use the following regexp, which should run at exactly the same speed as your original:

/^(\S+).*?\[(\S+).*?] (\S+) "(.+)" (\d+)/

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://36262]
[Discipulus]: I miss a bit the sunny balconny of my previous flat.. but since june to september is better facing north
[Corion]: Discipulus: Yeah, I can see that reasoning :) But spending 5 minutes in the sun today quite improved my mood :)
[marto]: lazyweb Q: so an IE window apparently opened via JS with toolbars=no, all other IE instances closed. Click a URL in an email or whatever, and it doesn't open a new window or tab.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2018-03-21 11:30 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (267 votes). Check out past polls.