Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards

Mark Solution

Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.

GELÖST

classification builder - regex for multiple values that adjust

Avatar

Level 6

Hi All,

Having some difficulties figuring out how to create regex that adjusts to the number of groups.

I can have any number of parts ranging from 1 to 4

strings:

events:company-conferences/company-user-conference/2018

events:company-conferences/company-user-conference

events:company-conferences

I tried this regex however it only returns the correct values if it has 4 capture groups, no more no less.

^([^\:]*)\:([^\:]*)\/([^\:]*)\/([^\:]*)

1525466_pastedImage_8.png

I tried the below regex however it does the same

^(.+)\:(.+)\/(.+)\/(.+)

is there regex logic that is flexible to the number of capture groups in a string? I would like to capture string that have groups up to 4 but may have 3 or 2.

any help would be highly appreciated.

thanks

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Level 1

Something like : ^(.+)\:(.+?)(\/|$)(.*?)(\/|$) (repeating (.*?)(\/|$) to the number of possible results will get you in even numbered fields the results you want.  So for 1-4:

^(.+)\:(.+?)(\/|$)(.*?)(\/|$)(.*?)(\/|$)(.*?)(\/|$)

You can see the results here: https://regexr.com/3sjh5

Lösung in ursprünglichem Beitrag anzeigen

3 Antworten

Avatar

Level 3

I do something similar in which I essentially have a different rule for either 5 or 6 fields.  Not sure if there is a more robust way but this should be easy to build from for 2/3/4 fields.  As an FYI my deliminator is an underscore.

^((.+)\_(.+)\_(.+)\_(.+)\_(.+)\_(.+)|(.+)\_(.+)\_(.+)\_(.+)\_(.+))$

sample Regex.png

Avatar

Korrekte Antwort von
Level 1

Something like : ^(.+)\:(.+?)(\/|$)(.*?)(\/|$) (repeating (.*?)(\/|$) to the number of possible results will get you in even numbered fields the results you want.  So for 1-4:

^(.+)\:(.+?)(\/|$)(.*?)(\/|$)(.*?)(\/|$)(.*?)(\/|$)

You can see the results here: https://regexr.com/3sjh5

Avatar

Community Advisor

Check out this thread see if it helps.

Regex help in Classification Rule Builder