0

I have the somehow weird requirement that several regex should be passed as one single string to a jenkins plugin.

They should be entered in one single textfield and I have to split this string in a List of Regex later on.

Now the issue is, I can't think of any way to delimit the regexes in the string so I can later split this string as a character like a , could also be considered part of a regex itself.

E.g. if I'd use a , for the two regex "(\d+,?\s+\d{1})\.xls" and "\w+\.exe" :

"(\d+,?\s+\d{1})\.xls,\w+\.exe"

would be split into 3 regexes: "(\d+", "?\s+\d{1})\.xls" and "\w+\.exe" where the first 2 are obviously invalid.

So my actual question is, are there any characters, that can never appear in a regex which I could use to delimit my regexes?

Igl3
  • 4,900
  • 5
  • 35
  • 69
  • Use a combination of chars that are invalid as per your regex engine. E.g. `<<++>>` if your engine does not support possessive quantifiers. – Wiktor Stribiżew Apr 11 '18 at 09:27

1 Answers1

0

No, any and all characters can appear in a regex. Use any serialisation format to serialise your list of strings into a clearly expressed list format, e.g. JSON:

["(\\d+", "?\\s+\\d{1})\\.xls", "\\w+\\.exe"]

Alternatively CSV or anything else that can express a list of things and properly escapes characters used to denote item separators.

deceze
  • 510,633
  • 85
  • 743
  • 889