I have the following string:
“Perl is the only language that looks the same before and after RSA encryption.” 🙂
This pattern "\\p{javaUpperCase}.*\\." looks for uppercase character and period. It returns true for that string, but if I remove word “Perl” it’ll give me false. Why is that? There’s still “RSA” word, which is uppercase too.
\p{javaUpperCase} – stands for UpperCase character
. means any character after that UpperCase
* is Greedy quantifiers, one or more times
\\. – period.
Where am I wrong? Why does it look only at the beginning and at the end?
Probably because it is trying to match the whole string. (Reference: http://www.regular-expressions.info/java.html says “It is important to remember that String.matches() only returns true if the entire string can be matched”). Depending on what regular expression library/function you use, it might require a match on everything.
Without “Perl”, the string doesn’t start with an uppercase character, so even though a substring matches, the whole string doesn’t.
Try
.*(\p{javaUpperCase}.*\.).*to match substrings.The
.*added on both ends allows extra characters on either end of the substring of interest.