Skip to main content
September 22, 2013
Answered

Parse String using RegEx REMatch

  • September 22, 2013
  • 1 reply
  • 777 views

Why does this not return the variable form.item_cost to equal:199.99?

<CFSET string1 = "Here we have $199.99 is the price">

<CFSET form.item_cost = "#reMatchNoCase("^\d{0,4}(\.\d{1,2})?$",string1)#">

I only want to match the first price it sees in the string and return that value as a numeric decimal.

This topic has been closed for replies.
Correct answer Adam Cameron.

Because you're anchoring the regex to the beginning and end of the string with ^ and $, you'll only match if the string in its entirey is the number.

I recommend using regex coach for testing this sort of thing. It makes it very easy to work this sort of thing out. http://www.weitz.de/regex-coach/

--

Adam

1 reply

Adam Cameron.Correct answer
Inspiring
September 22, 2013

Because you're anchoring the regex to the beginning and end of the string with ^ and $, you'll only match if the string in its entirey is the number.

I recommend using regex coach for testing this sort of thing. It makes it very easy to work this sort of thing out. http://www.weitz.de/regex-coach/

--

Adam