Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Nov 20, 2019 Nov 20, 2019

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.

 

 

 

 

TOPICS
Advanced techniques
558
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 21, 2019 Nov 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,

 

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 21, 2019 Nov 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 22, 2019 Nov 22, 2019

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

 

V/r,

 

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 23, 2019 Nov 23, 2019
LATEST

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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources