Given an arbitrary String
that contains 0
or more Substrings that match a regular expression.
How can I count the number of characters in that String
that were part of Substrings that matched the regex?
Example:
Given a regex that matches any email address and the String:
"I have two email addresses: email@gmail.com and email@hotmail.com"
This would return the int value of 32
(the number of characters in "email@gmail.com"
plus "email@hotmail.com"
).
I'm not being clear enough, it seems. Let's pretend you want to set a limit to the number of characters in a tweet, but you want to allow people to include their email address in the tweet and have it count as zero characters.
Possible method signature of solution:
public int lengthOfSubStringsMatchingRegex(String input, String regex)