Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Repeated code blocks in long and hairy regex

by ikegami (Patriarch)
on Nov 06, 2023 at 14:51 UTC ( [id://11155405] : note . print w/replies, xml ) Need Help??


in reply to Repeated code blocks in long and hairy regex

Those eval make no sense and you're missing the /x. You simply want

my $nfw_oang = qr% (?!\p{IsOang}(?! (?:\p{InThaiFinCons}){1,2} (?![\p{InThaiCompVowel}\p{InThaiPostVowel}\p{InThaiTone}]) (?:\p{InThaiMute}) )) %x;

And given that (?![\p{X}\p{Y}\p{Z}])\p{W} can be written as (?[ \p{W} - [\p{X}\p{Y}\p{Z}] ]) or (?[ \p{W} - \p{X} - \p{Y} - \p{Z} ]), you could use

my $nfw_oang = qr% (?! \p{IsOang} (?! (?:\p{InThaiFinCons}){1,2} (?[ \p{InThaiMute} - \p{InThaiCompVowel} - \p{InThaiPostVowel} - \p{InThaiTone} ]) ) ) %x;

That said, you might want to look into (?(DEFINE)...).

/ ... (?&NFW_OANG) ... (?&INITIAL_CONSONANT) ... (?(DEFINE) # NOT FOLLOWED BY O-ANG WITHOUT A THAI MUTE/CONSONANT ENDING (?<NFW_OANG> (?! (?&OANG) ) ) # O-ANG WITHOUT A THAI MUTE/CONSONANT ENDING (?<OANG> \p{IsOang} (?! (?:\p{InThaiFinCons}){1,2} (?[ \p{InThaiMute} - \p{InThaiCompVowel} - \p{InThaiPostVowel} - \p{InThaiTone} ]) ) ) # INITIAL CONSONANT(S) (?<INITIAL_CONSONANT> (?: \p{InThaiDualC1} \p{InThaiDualC2} | \p{InThaiCons} ) ) /x