while (1) { if (/\G($named)/gc) { print transform_named($1) } elsif (/\G($http)/gc) { print transform_http($1) } ... elsif (/\G(.)/gcs) { print $1 } else { last } }
Thanks I ended up using this approach, it's the most practical in my case! ¹
Actually I knew and tried it before w/o luck, turned up that the /\G(.)/gcs was crucial.
I remember \G to be tricky (or even buggy) in edge cases,
(Don't really know why I need /s since there are no line breaks in single lines? ...have still to debug whats going on with pos here...)
But it works now, thanks! =)
Cheers Rolf
( addicted to the Perl Programming Language)
¹) The code in the OP might be a good way to design a parser generator but I dont need the complexity and the extra speed of one big regex.
In reply to Re^5: Challenge: Transforming markups
by LanX
in thread Challenge: Transforming markups
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |