Skip to main content
Participant
Nov 21, 2019 5:06 AM UTC
Question

GetToken() - like function using a pattern, vs. a collection of delimiters

I would like to extract the nth occurance of a token from a string based on the position of a pattern matching more than one characters, vs. the single character list of delimiters that GetToken() supports. GetToken() is great in many contexts, but not this one! Haven't found anything in CFLib, but maybe I'm just looking in the wrong places. Seems like it should be a common need.

 

 

 

 

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

BKBK
Community Expert
Community Expert
Nov 23, 2019 2:43 PM UTC

From your description, I would have thought that REMatch or REMatchNoCase would be suitable. You would then get a result, from which you could simply red off searchMatchArray[n]

Translate
WolfShade
Legend
Nov 21, 2019 2:36 PM UTC

GetToken() and ListGetAt() both will treat multiple delimiter values as individual, not as a pattern.

 

I wonder if RegEx matching will get at least an index position, which you can use as you describe?

 

V/r,

 

^ _ ^

Translate
Rex-HavocAuthor
Participant
Nov 21, 2019 8:50 PM UTC

Appreciate the input WolfShade. Digging around a bit more came up with a nice component by Ben Nadel that I think meets this need:

RESplit() - Splitting Strings With Regular Expressions In ColdFusion

Translate
WolfShade
Legend
Nov 22, 2019 2:28 PM UTC

Good find.  Ben comes up with some pretty awesome scripts.  I especially like his reMultiMatch() function.

 

V/r,

 

^ _ ^

Translate