i have three string app, app_abc, appabc i want to replace any of the string with code (for replacing) output should be
- app -> code,
- app_abc -> code_abc,
- appabc -> appabc
i have tried this replaceAll("^app", code); but it will be replaced starting app
wrong output:
- app -> code,
- app_abc -> code_abc,
- appabc -> codeabc(i want to exclude this type of string using regex)
i know i have to use or oprator so i have tried this
replaceAll("^app|app_(?!(.*))", code);
https://regex101.com/r/Ils9kM/1
but it is wrong i think anyone can suggest ?
replaceAll("^app(?!abc)", "code")appwhen it is at the beginning of a string but not followed by any letter?replaceAll("\\bapp(?![a-zA-Z])", "code");or the pattern can also be"\\bapp(?=\\b|_)"