Link to home
Start Free TrialLog in
Avatar of SiobhanElara
SiobhanElaraFlag for United States of America

asked on

How should I format a regex for a positive lookbehind in ColdFusion?

I have a string that contains a path, like "this/is/a/path/to/the/root/subfolder". I'm attempting to get everything after "root" (in this case "/subfolder".)

According to the documentation at regular-expressions.info, (?<=s)t should match the first "t" in "streets". I used that to make this:

<cfset regex = "(?<=root).*">
#REFind(regex, myString)#

Open in new window


This gives me the error "Reason: Sequence (?<...) not recognized."

I've Googled up a storm and tried escaping characters, changing the parentheses... but the most common error that throws is "?+* follows nothing in expression" with the occasional "Malformed regular expression" "?<="".

I'm at a loss. Can you help? Thanks!
Avatar of Coast Line
Coast Line
Flag of Canada image

try using like this


<cfset filepath = "this/is/a/path/to/the/root/subfolder">

<cfset fileName = ListLast(filePath, "/")>
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SiobhanElara

ASKER

Thank you kaufmed and _agx_! I didn't know that about CF and the lookbehind.

(myselfrandhawa, I might also have something like this/is/a/path/to/the/root/subfolder/and/another, so I can't use ListLast. But thank you for the suggestion!)