Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: regular expression help

by ikegami (Pope)
on Jun 03, 2009 at 19:54 UTC ( #768139=note: print w/replies, xml ) Need Help??


in reply to regular expression help

To match "X,X,X", the pattern will look something like /X(?:,X)*/. Since your "X" is rather long, you might want to consider splitting on commas first, then parsing each item in the list.

Replies are listed 'Best First'.
Re^2: regular expression help
by Roy Johnson (Monsignor) on Jun 03, 2009 at 20:00 UTC
    ...consider splitting...
    Or define your X subpattern as a separate regex, then build the pattern with it:
    my $subpat = qr/(?:<\*\d+>)?([^<]+)<(\d+):(\d+)>/; $str =~/$subpat(?:,$subpat)*/;
    However, the capturing parentheses are not going to capture everything this way.

    Caution: Contents may have been coded under pressure.

      However, the capturing parentheses are not going to capture everything this way.

      That's why I didn't recommend it. Perl's match operator can match extremely complex expressions (the initial purpose of regular expressions) and it can extract data from strings, but it's not so good at doing both at once. (At least not before 5.10. 5.10 added a bunch of tools that might help.)

      Thanks for the suggestion...I will try doing something like this!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://768139]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-11-23 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (340 votes). Check out past polls.

    Notices?