Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I know I can use the find funct

Status
Not open for further replies.

kjeff215

MIS
Mar 19, 2002
17
US


I know I can use the find function to search for a defined particular string. But how do I search for a undefined length string For example I am looking for the "***#Userid#***" string inside of a header. But this number can range in value so do I need to search like this
findnocase("***[0-100000000]***",mystring,1)
 
It sounds like you need to use REFind() or REFindNoCase(), which accomplish basically the same function as Find() and FindNoCase() (respectively) but allow you to use regular expressions in the search criteria.

I'm not sure exactly what the range of allowable values are for the UserID in your example, but if you're looking for three asterisks followed by an any number of numeric digits, followed by three asterisks, your call to ReFindNoCase() would look like this:
Code:
   #REFindNoCase
   (
      "\*\*\*[[:digit:]]*\*\*\*",
      myStringVar
   )#

If you're looking to extract the UserID, you can use REReplaceNoCase(), like so:
Code:
   <cfset UserID = 
      REReplaceNoCase
      (
         myStringVar,
         &quot;^.*\*\*\*([[:digit:]]*)\*\*\*.*$&quot;,
         &quot;\1&quot;
      )
   >
which would store just the value of the UserID in the variable #UserID#.
 
REFind(), REFindNoCase will return the position of the first occurrence of a regular expression in a string starting from a specified position. Returns 0 if no occurrences are found. This example will search for numeric characters but you can replace that and search for alpha numeric characters if needed ([a-z,A-Z,0-9]):

<cfset userID = REFind(&quot;[0-9]&quot;, mystring)> Sylvano
dsylvano@hotmail.com
 
whoa,
REReplaceNoCase(GetMessages.hdrall_,&quot;^.*\*\*\*([[:digit:]]*)\*\*\*.*$&quot;,&quot;\1&quot;) > works beautifully!!!thanks pcorreia

Havent tried the other method yet, WWebspider(still very much appreciated!)

May I ask one more question while I have the attention of two gurus?

Is there a way to reject the cfid and cftoken in the url. Or is this just a coldfusion glitch. A user/hacker could actually created their own urltoken and send it out to others and gain access to user accounts. Is there a way to tell Cfserver to ignore cfid and cftoken in the url
 
the cf runs the application.cfm template before any other requested template is executed; if you want to reject cfid and cftoken from url, you can specify that in the application.cfm template;
if you write something like IsDefined(&quot;url.cfid&quot;) AND IsDefined(&quot;url.cftoken&quot;) to check if those exist, cf &quot;knows&quot; that attempt is made to pass cfid and cftoken through the url and you can write custom action based on that;

one note though, passing cfid and cftoken through the url is used to maintain session when user have cookies disabled; consider scenario where user have cookes disabled and you don't let cfid and cftoken to be passed through the url - the cf will have no way of recognizing the visitors Sylvano
dsylvano@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top