I have JTextPane which colors "int" words blue. Such regexp is wrong because it will also color "print":
int + "(\\[\\])*" //To match eg. int[]
So I came on idea with such regexp:
"\\s" + int + "(\\[\\])*"
Its okay but doesnt work if user types int as first in text pane. How to solve this problem? Is there some symbol for NOTHING? So i could make: \s | NOTHING
Just match int
surrounded by word boundaries, which are matched by \b
. The pattern:
"\\bint\\b"
More reading over at the always-excellent regular-expressions.info.
Do you want an optional space? That would be \\s?
. Or to allow zero or more spaces: \\s*
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With