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 protected] and [email protected]"
This would return the int value of 32
(the number of characters in "[email protected]"
plus "[email protected]"
).
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)