In my Android project I have a regular expression and a string, in which I should have the matched expression. The problem is, I’ve only found a matches() method, which returns boolean. Is there something, which returns only the matched string (for instance, if my string is “go to the shop at 12pm”, I want to check if there is a time in this string (in this example – “12pm”), if it is – return it) ?
Thanks in advance.
In my Android project I have a regular expression and a string, in which
Share
you should get capturing group you need. Read this. You’ll find answer to your question.
Here is a simple example for you. I think you’ll understand it.
This will return
12pmActually you can get what you want with better way.