-1

I am trying to replace all instances of a substring from the first character following ":" until the end of a substring "user" with case-ignored using the (?i)

So, an example would be:

Input

u:sdneUSER|r:endsUser(&g:againuser)

Replace All :

sdneUSER -> root
endsUser -> root
againuser -> root

Expected Output:

u:root|r:root(&g:root)

Reference :

Ignore case https://stackoverflow.com/a/5055036

YCF_L
  • 51,266
  • 13
  • 85
  • 129
nelloreg
  • 11
  • 1
  • 1
    you should at least try – Stultuske Jan 14 '18 at 18:28
  • Your question only contains requirements - it is not showing any efforts from your side to solve this problem yourself. Please add your attempts to this questions - as this site is not a free "we do your (home)work" service. Beyond that: please turn to the [help center](https://stackoverflow.com/help) to learn how/what to ask here. Thanks – azro Jan 14 '18 at 18:28
  • Please show what you have tried. This site is great at helping you improve what you have done but no so good at doing the work for you. – Rob Anthony Jan 14 '18 at 18:35

1 Answers1

0

You can use this regex :.*?(?=[^a-zA-Z]+) with replaceAll like this :

String text = "u:sdneUSER|r:endsUser(&g:againuser)";
text = text.replaceAll(":.*?(?=[^a-zA-Z]+)", ":root");

Output

u:root|r:root(&g:root)

regex demo

YCF_L
  • 51,266
  • 13
  • 85
  • 129