I am trying to learn the basics of regular expressions (in Java) and imagined some sample scenarios to practice, and – as you might have expected – the last (and thus for me hardest) isn’t working. Here it is:
<[a-zA-Z]>:[a-zA-Z]
What I want it to do is to recognize <SOME TEXT>:SOME MORE TEXT. With input like: <foo>:bar, it isn’t working.
What am I doing wrong?
You’re only matching one character. To match multiple, you need to add ‘+’:
If the text is optional, you can also specify ‘*’, which means “zero or more”. ‘+’ means “1 or more”