Welcome to Dream.In.Code
Getting Help is Easy!

Join 118,873 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,822 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



reFindNoCase not returning expected subexpressions

 
Reply to this topicStart new topic

reFindNoCase not returning expected subexpressions

sansclue
post 21 Nov, 2007 - 09:57 PM
Post #1


D.I.C Head

**
Joined: 21 Nov, 2007
Posts: 88



Thanked 4 times
My Contributions


Hi - First post here.

I'm trying to search a string for all values enclosed in a tilde ~. But its not working the way I expected. With the test string:


myString = this is a ~test~ ~some~ of the values are ~enclosed~ in a ~tilde~ symbol



I would have expected it to find these words:

test some enclosed tilde

But it only finds ~test~.

Is what I'm trying to do even possible? If it is, I would love it if someone could help me understand why the attached code doesn't work. Its bugging the heck out of me!


CODE

<cfset myString = "this is a ~test~ ~some~ of the values are ~enclosed~ in a ~tilde~ symbol">
<cfset result = reFindNoCase("~([^~]*)~", myString, 1, "true")>
<cfoutput>
myString = #myString#<br>
results:<br>
<cfloop from="1" to="#arrayLen(result.pos)#" index="i">
    #mid(myString, result.pos[i], result.len[i])#<br>
</cfloop>
</cfoutput>
User is offlineProfile CardPM

Go to the top of the page


sansclue
post 29 Nov, 2007 - 04:58 PM
Post #2


D.I.C Head

**
Joined: 21 Nov, 2007
Posts: 88



Thanked 4 times
My Contributions


Anybody?
User is offlineProfile CardPM

Go to the top of the page

sansclue
post 10 Dec, 2007 - 12:43 AM
Post #3


D.I.C Head

**
Joined: 21 Nov, 2007
Posts: 88



Thanked 4 times
My Contributions


Is this one a stumper, silly question or does this forum not get much traffic at all ?
User is offlineProfile CardPM

Go to the top of the page

skyhawk133
post 10 Dec, 2007 - 07:38 AM
Post #4


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,608



Thanked 39 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


reFindNoCase will only find the first occurence of a string. Since reFindNoCase returns the position and length, you can do a while loop and keep calling reFindNoCase with the position+length+1 as the start position which will find the first instance, then start at the next character in the string after the first occurance and search again, it would continue to do this as long as reFindNoCase was returning true.

Hope that helps.
User is offlineProfile CardPM

Go to the top of the page

sansclue
post 10 Dec, 2007 - 08:32 PM
Post #5


D.I.C Head

**
Joined: 21 Nov, 2007
Posts: 88



Thanked 4 times
My Contributions


QUOTE(skyhawk133 @ 10 Dec, 2007 - 07:38 AM) *

reFindNoCase will only find the first occurence of a string. Since reFindNoCase returns the position and length, you can do a while loop and keep calling reFindNoCase with the position+length+1 as the start position which will find the first instance, then start at the next character in the string after the first occurance and search again, it would continue to do this as long as reFindNoCase was returning true.

Hope that helps.


Thanks. Doh. I can see I'm confusing find with REReplaceNoCase with its "all" scope. Of course its a totally different function wink2.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/13/08 02:15AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month