How do I parse out text from a string and set it as a variable example....

<cfset searchstring = "Pays up to $1,000 a day up to 100 days">

I need to set as a variable "DailyHospital" = $1,000 a day from string above.
The amount will change but the xxx "a day" will be constant.

How do I pull that out starting at $ and ending on day?

LeadCoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jones911Commented:
<cfset searchstring = "Pays up to $1,000,00.00 a day up to 100 days" />
<cfset DailyHospital = left(right(searchstring,len(searchstring)-11),len(searchstring)-25) />
<cfdump var="#DailyHospital#" />
0
Jones911Commented:
That should do it for any amount.  This could also be done with a regEx.
0
_agx_Commented:
Yes, there are a bunch of ways to do it.  Here is one example of a regex.  You could also use reReplace, but personally I prefer using reMatch and using arrayLen to confirm a match was found.  A few times I have overlooked  the fact that reReplace did not actually find a match, which caused problems ;-)  That is just my personal preference though.


<cfset searchstring = "Pays up to $1,000 a day up to 100 days">
<cfset matches = reMatchNoCase("(\$[0-9,]+\s+a\s+day)", searchString)>
<cfset DailyHospital = "not found">
<cfif arrayLen(matches)>
	<cfset DailyHospital = matches[1]>
</cfif>
<cfoutput>
DailyHospital = #DailyHospital#
</cfoutput>

Open in new window

0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

abu3antarCommented:
I used to do this technique and it worked fine for me:
    <cfset start = REFind('$',searchstring)>   <!--------Find that start point------>
    <cfset end = REFind('a day', searchstring,start)>   <!--------Find that end point------>
    <cfset DailyHospital = trim(mid(searchstring,start,end-start))>   <!--------Extract the in between------>

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
_agx_Commented:
If you are not using regular expressions, you may as well just use a plain find(..). Though a case insensitive search would be better.  However, a regular expression search would be the most flexible. It would be able to handle things like a varying number of spaces, whereas a regular find will not.
0
Jones911Commented:
All 3 will work fine.
0
LeadCoAuthor Commented:
Thanks Guys!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.