I want to write a java Regular expression that recognises the following patterns.
abc def the ghi
and abc def ghi
I tried this:
abc def (the)? ghi
But, it is not recognizing the second pattern.Where am I going wrong?
I want to write a java Regular expression that recognises the following patterns.
abc def the ghi
and abc def ghi
I tried this:
abc def (the)? ghi
But, it is not recognizing the second pattern.Where am I going wrong?
Spaces are also valid characters in regex, so
can match only
or when we remove
the
wordYou need something like
abc def( the)? ghi
to also make one of these spaces optional.Remove the extra
space