Best delimiter to separate multipe regex
delimiter, java, parsing, regex
Solution
The best way would be to use invalid regex as delimiter such as `**` Because if it is used in normal regex it won't work and would throw an exception{NOTE:`++` is valid}
regex1+"**"+regex2
Now you can split it with this regex
(?<!\\\\)[*][*](?![*])
------- -----
| |->to avoid matching pattern like "A*"+"**"+"n+"
|->check if * is not escaped
Following is a list of invalid regex
- [+
- (+
- [*
- (*
- [?
- *+
- ** (delimiter would be `(?<!\\\\)[*][*](?![*])`)
- ??(delimiter would be `(?<!\\\\)[?][?](?![?])`)
While splitting you need to check if they are escaped
(?<!\\\\)delimiter
Problem
I need to put multiple regular expressions in a single string and then parse it back as separate regex. Like below ``` regex1<!>regex2<!>regex3 ``` Problem is I am not sure which delimiter will be best to use to separate the expressions in place of `<!>` shown in example, so that I can safely split the string when parsing it back. Constraints are, I can not make the string in multiple lines or use xml or json string. Because this string of expressions should be easily configurable. Looking forward for any suggestion. Edited: Q: Why does it have to be a single string? A: The system has a configuration manager that loads config from properties file. And properties are containing lines like ``` com.some.package.Class1.Field1: value com.some.package.Class1.Expressions: exp1<!>exp2<!>exp3 ``` There is no way to write the value in multiple lines in the properties file. That's why.