Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Complex Splitting

by holli (Abbot)
on Feb 06, 2007 at 13:40 UTC ( [id://598533]=note: print w/replies, xml ) Need Help??


in reply to Complex Splitting

Quickshot:
push @array, $2 ? $2 : $3 while $str =~ /(([A-Z])|\[([A-Z]+)\])/g;


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Complex Splitting
by diotalevi (Canon) on Feb 07, 2007 at 07:58 UTC

    In perl 5.10, you don't need to do backflips to get away from the "extra" captures. (?^...|...) means the captures get renumbered so here both are $1. Only one ever actually matches at any time so there's no conflict.

    push @array, $1 while $str =~ /(?^(\w+)|\[(\w+)\])/g;

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2025-07-18 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.