Abdullq Abdullq - 4 months ago 12
Java Question

How to match all the character after a word

I have this sentence "I am a boy with French - Glukker Man". I want to match every character after French so that the regex highlights " - Glukker Man". Currently I am using this: Currently I am doing:

(french[\s\S]*?)


But it's highlighting only "French".
This is the regex test

Please, how do I do it?

Answer

Use a positive lookbehind to match french, then select everything after it with .*:

(?<=french)(.*)

Then you can use it in your replacement:

<center>$1</center>

Alternatively, you could just match french and then only capture what comes after it.

french(.*)

In this case it looks like you're trying to surround your match with <center></center>, so for the second example to work, you'd have to capture french in its own group and put it back, or have it in your replacement:

Regex: (french)(.*)
Replacement: $1<center>$2</center>

Or

Regex: french(.*)
Replacement: french<center>$1</center>
Comments