Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract substring in java using regex

Tags:

java

regex

I need to extract "URPlus1_S2_3" from the string:

"Last one: http://abc.imp/Basic2#URPlus1_S2_3," 

using regular expression in Java language.

Can someone please help me? I am using regex for the first time.

like image 357
Niras Avatar asked Apr 17 '26 21:04

Niras


1 Answers

Try

Pattern p = Pattern.compile("#([^,]*)");
Matcher m = p.matcher(myString);
if (m.find()) {
  doSomethingWith(m.group(1));  // The matched substring
}
like image 60
Mike Samuel Avatar answered Apr 19 '26 09:04

Mike Samuel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!