Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Splitting string using two overlapping patterns

by Lennotoecom (Pilgrim)
on Oct 24, 2013 at 20:10 UTC ( [id://1059542]=note: print w/replies, xml ) Need Help??


in reply to Splitting string using two overlapping patterns

$line = 'Iteration {Applied Field} A {Total Energy} Mx F G {Third + test line}'; print "$&\n" while $line=~s/(?<={)[\w\s]+(?=})|\w+//; Iteration Applied Field A Total Energy Mx F G Third test line

Replies are listed 'Best First'.
Re^2: Splitting string using two overlapping patterns
by AnomalousMonk (Archbishop) on Oct 24, 2013 at 21:28 UTC
    print "$1\n" while $line=~s/(\w+\s+\w+|\w+)[}|\s+|\s+{]//;

    Metacharacters like  | are not meta-special in a character class, so  [}|\s+|\s+{] from the quoted regex is equivalent, with the pipe metacharacter explicitly escaped (for clarity), to  [\s{}\|] or, less verbosely, to the  [\s{}|] class. (In other words, there's no alternation in a character class.)

      noted.
      thank you
      I corrected my previous version,
      because it contained a serious mistake

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-16 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found