Abdullq
Abdullq

Reputation: 69

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?

Upvotes: 0

Views: 60

Answers (3)

arjnklc
arjnklc

Reputation: 155

You can use split to do that in Java. Just split the string with the word that you want then use the second part of it.

String str = "I am a boy with French - Glukker Man";
String str2 = str.split("French")[1];
System.out.println(str2);

Output is: " - Glukker Man"

Upvotes: 0

uamanager
uamanager

Reputation: 1248

(french[\s\S](.*))

use 2nd group to highlight it

Upvotes: 0

nickb
nickb

Reputation: 59699

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>

Upvotes: 3

Related Questions