I am using reMatch
to get the matched substring from a list. But when I am using prefix lookaround then I am getting error.
Sequence (?<...) not recognized
Code:
<cfset local.path = "schedule.category.classes.name,schedule.category.classes.id">
<cfset local.regex = "(?<=schedule.category.classes.)[a-zA-Z0-9_]*?(?=,|$)">
<cfset local.output = reMatch(local.regex, local.path)>
What am I missing?
You're missing the bit about reading the docs ;-) - Regular expression syntax - Using special characters - Look behinds & arounds are not supported in CFML's flavour of regex (which is long-dead Apache ORO).
However it's easy enough to use java's regex implementation instead, which does support look-behinds: java.util.regex.Pattern - Special constructs (named-capturing and non-capturing).
I have written two parts of a three part series on using Java regexes in CFML: "Regular expressions in CFML (part 9: Java support for regular expressions (1/3))". I must get back to doing part 3 at some point, but what you need is in the first coupla parts anyhow.
Ben Nadel also writes extensively on using Java regexes in CFML. Just do a quick google if you get stuck having looked @ my notes (but let me know where you get stuck if you do, so I can revisit my wording!).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With