I have a string with a number inside and I want to get that number. for example, if I have the line "bla bla 45 bla bla", I want to get the number 45. I searched a bit and found out that this code should do the job
Matcher matcher = Pattern.compile("\\d+").matcher("bla bla 45 bla bla"); if(matcher.matches()) String result = matcher.group();
but this is not so :(
probably the problem is that the regular expression "\ d +" is converted to "^ \ d + $", and therefore the match does not match the number inside the text.
Any ideas.
source share