Reputation: 1167
[https://regex101.com/r/qNDKIh/1/][1]
How can I convert a working regular expression in regex101 to Coldfusion REMatchNoCase [1]: https://regex101.com/r/qNDKIh/1/
Coldfusion Code
<cfset VinDetail = ReMatchNoCase("^([A-HJ-NPR-Z0-9]{3})([A-HJ-NPR-Z0-9]{5})([0-9X])([A-HJ-NPR-Z0-9])([A-HJ-NPR-Z0-9])([A-HJ-NPR-Z0-9]{6})$", "1G1PA5SH9D7126083") />
<cfdump var="#VinDetail#">
Getting Malformed regular expression
error
Regex101 output
Full match 0-17 1G1PA5SH9D7126083
Group `wmi` 0-3 1G1
Group `vds` 3-8 PA5SH
Group `check` 8-9 9
Group `vis` 9-17 D7126083
Group `year` 9-10 D
Group `plant` 10-11 7
Group `seq` 11-17 126083
Upvotes: 1
Views: 173
Reputation: 1295
The single result matching the input string is 'correct' - because ReMatch()
only returns matches, and that is the actual match. If you want to return the capture groups then you can use ReFind()
with returnsubexpressions=true
, eg:
<cfset VinDetail2 = ReFindNoCase("^([A-HJ-NPR-Z0-9]{3})([A-HJ-NPR-Z0-9]{5})([0-9X])(([A-HJ-NPR-Z0-9])([A-HJ-NPR-Z0-9])([A-HJ-NPR-Z0-9]{6}))$", "1G1PA5SH9D7126083", 1,true,'ALL') />
<cfdump var="#VinDetail2[1].MATCH#" />
<cfdump var="#VinDetail2#" />
Upvotes: 1