I would like to know if their is a function in JAVA that allows to retrieve from a huge string a char sequence that contains a special char.
Example: I have a php page that that I've stringified and I check if there is a char sequence containing the char "@". If it's the case, I would like to get just the whole char sequence that contains the searched char.
I can use String.contains("@") to look for the char but how to get the char which contains it ?
Thanks in advance !
You can use a regular expression based on
"mailto = ([email protected])"
If this is found in the stringified php, you can conveniently extract the parenthesized section.
But most likely it could be
[email protected]
as well, and so you may have to write a more complicated regular expression, but it'll work the same way.Here's a version matching any valid email address:
Perhaps the spaces before and after
=
aren't guaranteed, so you might make them optional:To execute the match, use
and, with the php in a String you can then do
The find can be called repeatedly to find all occurrences.
See another SO Q+A for the discussion of a regular expression matching an email address.