Skip to main content
New Participant
November 21, 2019
Question

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

  • November 21, 2019
  • 2 replies
  • 563 views

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 has been closed for replies.

2 replies

BKBK
Community Expert
November 23, 2019

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]

WolfShade
Brainiac
November 21, 2019

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,

 

^ _ ^

Rex-HavocAuthor
New Participant
November 21, 2019

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

WolfShade
Brainiac
November 22, 2019

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

 

V/r,

 

^ _ ^