Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: bracket processing

by LanX (Saint)
on Mar 31, 2020 at 01:26 UTC ( [id://11114820]=note: print w/replies, xml ) Need Help??


in reply to bracket processing

I'm not sure about your "longest greedy" requirement and if it really had to be one single regex.

I'd go for a KISS approach to apply multiple replacements of non nested pairs with placeholders.

0: The use of parentheses (indicates that the (writer [considered] the {information}) less <important—almost> an afterthought).

1: The use of parentheses (indicates that the (writer  %0% the %1%) less %2% an afterthought).

2: The use of parentheses (indicates that the %3% less %2% an afterthought).

3: The use of parentheses %4%.

This can be done by repeating one simple regex over and over and storing the matches in an array. Afterwards you just need to reconstruct the tree again.

NB: I just used %n% for visualization. Using something like \0 is far better here.

HTH :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

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

    No recent polls found