I have a requirement where the string has to contain _exact. I am using Java.
- If the string has a locale (
_enor_ja) at the end, add _exact before the locale. - If
_exactis already present, don't add it again. - If no locale at the end, and no exact, add
_exactat the end of the string.
E.g.:
something->something_exactsomething_en->something_exact_ensomething_ja->something_exact_jasomething_exact_en->something_exact_ensomething_exact->something_exact
I spent some time and came up with 2 regex that, if ran in succession on the same string, make it possible. I am not sure if they cover all the possible cases though.
^(.*)(?<!_exact)(_(?:en|ja))$
^(.*)(?<!_exact)(?<!_(?:en|ja))$
If anybody could help me come up with just 1 regex that does the job, it would be great! Thank you!
.+?matches 1 or more chars , and I used.*?, 0 or more chars at the start.