Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex prefix lookaround not working in coldfusion 10

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?

like image 646
Beginner Avatar asked May 04 '15 08:05

Beginner


1 Answers

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!).

like image 142
Adam Cameron Avatar answered Sep 21 '22 09:09

Adam Cameron