Getting only required value using regex?

I have the following date and i just to extract the following from the string

25

from
+25 15:12:00.000000

Please guide
LVL 16
Gurpreet Singh RandhawaWeb DeveloperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
PluckaConnect With a Mentor Commented:
<cfset data = "+25 15:12:00.000000" />
<cfset result = listFirst(data, " +") />

NOTE: thats a SPACE and a + in the quotes on the second line
0
 
Brijesh ChauhanStaff IT EngineerCommented:
You can use DAY() function ?
0
 
Brijesh ChauhanConnect With a Mentor Staff IT EngineerCommented:
<cfset dayString = '+25 15:12:00.000000' />

<cfset dayString = replace(dayString,'+','','ALL') />

<cfset date = left(daystring,2) />

<cfoutput> #date# </cfoutput>

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
that wil alos help if the value after +1056 blah blah

right plucka

it will extract 1056
0
 
PluckaCommented:
yes, it treats the string as a list, uses either SPACE or + as a seperator and gets the first item.
0
 
Brijesh ChauhanStaff IT EngineerCommented:
you didn't specify it can be more than 2 characters.. here will work with dynamic


<cfset dayString = '+25234 15:12:00.000000' />

<cfset dayString = replace(dayString,'+','','ALL') />

<cfset count = find(' ','#dayString#') />

<cfset date = left(daystring,count) />

<cfoutput> #date# </cfoutput>

Open in new window

0
 
Brijesh ChauhanStaff IT EngineerCommented:
Explanation.. remove the + sign, get the blank where it occurs, then get count characters from the string..

<cfset dayString = '+1056 blah blah 15:12:00.000000' />

<cfset dayString = replace(dayString,'+','','ALL') />

<cfset count = find(' ','#dayString#') />

<cfset date = left(daystring,count) />

<cfoutput> #date# </cfoutput>

Open in new window


this will output date as 1056 ..... Test it out..
0
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
i want that beforethe .dot sign it shuld just pick the chracters

leave the + n space, i am sorry for this

19.3999999999999
0
 
Brijesh ChauhanStaff IT EngineerCommented:
didn't get what you want to extract ?? above example is not very clear...
0
 
Brijesh ChauhanStaff IT EngineerCommented:
<cfset dayString = '+1056 blah blah 15:12:00.000000' />

<cfset dayString = replace(dayString,'+','','ALL') />

<cfset count = find('.','#dayString#') />

<cfset count = count - 1 />

<cfset date = left(daystring,count) />

<cfoutput> #date# </cfoutput>

Open in new window


would return '1056 blah blah 15:12:00' .. is that what you are looking for ????
0
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
Guys, Plesae levae off the + and the space

just wanna get

19

from
19.27364582364782647826472634862347826834724
0
 
Brijesh ChauhanStaff IT EngineerCommented:
Here you go... this is dynamic

<cfset dayString = '19.27364582364782647826472634862347826834724' />
<cfset count = find('.','#dayString#') />
<cfset count = count - 1 />
<cfset date = left(daystring,count) />
<cfoutput> #date# </cfoutput>

Open in new window

0
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
Thanks, but nw i am getting this issue

The 2 parameter of the Left function, which is now -1, must be a positive integer
0
 
Brijesh ChauhanStaff IT EngineerCommented:
what is the string that you are checking ??? that will only come if you do not have a "." in your string...
0
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
i am checking the same above u are telling me same scenario
0
 
Brijesh ChauhanStaff IT EngineerCommented:
You are checking the below code ??? it works correctly for me.. even I changed the string to 19273645823.64782647826472634862347826834724 and 1927364582364.782647826472634862347826834724, the only way I get the error you have posted is when there is no period in string, in that case count would be zero and count - 1 would be -1 and that gives you the error....

<cfset dayString = '19.27364582364782647826472634862347826834724' />
<cfset count = find('.','#dayString#') />
<cfset count = count - 1 />
<cfset date = left(daystring,count) />
<cfoutput> #date# </cfoutput>

Open in new window


can you post the portion of code that you are using ??
0
 
käµfm³d 👽Connect With a Mentor Commented:
Here's my contribution.

Given: +25 15:12:00.000000

<CFSet data = '+25 15:12:00.000000' />
<CFSet extracted=REReplace("#data#", "^.*?\+(\d+).*$", "\1") />
<CFDump var=#extracted# label="href" />

Open in new window



Given: 19.27364582364782647826472634862347826834724

<CFSet data = '19.27364582364782647826472634862347826834724' />
<CFSet extracted=REReplace("#data#", "^.*?(\d+)\..*$", "\1") />
<CFDump var=#extracted# label="href" />

Open in new window

0
 
gdemariaConnect With a Mentor Commented:

There is a simplier way, you just need to use the list functions.

This one line will do it for you...

<cfoutput>#listFirst(data,".+- ")#</cfoutput>


Try the code below...
<cfset data = '-19.27364582364782647826472634862347826834724'>

<cfoutput>#listFirst(data,".+- ")#</cfoutput>

<cfset data = '+25 15:12:00.000000' />

<cfoutput>#listFirst(data,".+- ")#</cfoutput>

Open in new window

0
 
käµfm³d 👽Commented:
@gdemaria

That was mentioned above  http:#35025045 .   = )
0
 
gdemariaCommented:
> That was mentioned above  

Almost, but not quite.   The author changed (or added to) his requirements to also take the absolute value of a negative value and to truncate at the decimal point.

I added those two additions to cover all requirements.  

The list function is very simple and reliable.
0
 
käµfm³d 👽Commented:
Point taken  : )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.