This is my first time working with regular expressions and I’ve been trying to get a regular expression working that would match the following:
- apple
- apple inc.
- apple co.
- apple corp.
but would not match:
- inc. apple
- co. apple
- apple co. inc.
- apple corp. inc.
- apple inc. corp.
- and so on…
This is what I got so far (apple)\s(inc|corp|co).$
Think you could help 🙂
EDIT: It needs to work in Java. Does java have it’s own syntax for Regular Expressions?
You’re almost there:
Note that if you want your regexp to be case insensitive, you either have to pass the
CASE_INSENSITIVEflag when constructing the pattern or add(?i)to the pattern.