How to check if a word ends with parenthesis I.e word(s) using Java and regex? -


i tried creating regex me solve below problem not able to:

example word : mumbai(10)

the regex should check if word ending parenthesis value i.e (10) in above word "mumbai(10)". , value should extracted i.e 10.

if word mum(10)bai no results should output.

string string = "mumbai(10)"; pattern p = pattern.compile("^.*\\((\\d+)\\)$"); matcher m = p.matcher(string); if (m.matches()) {     system.out.println(m.group(1)); } 

^ , $ denote beginning , end respectively. .* matches anything. parenthesis need escaped, since represent group in regular expression, being made use of after that. captured group can extracted using m.group(1).


Comments

Popular posts from this blog

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

node.js - Using Node without global install -

java - JavaScript + Thymeleaf - select onchange -