NullPointer0x00
NullPointer0x00

Reputation: 1858

Regex in java and ignoring white spaces

I want to write a regex to match on a string and ignore white spaces. For example, a search for 'foobar' would match on 'foo bar'.

Upvotes: 1

Views: 2938

Answers (1)

NullUserException
NullUserException

Reputation: 85458

You can strip the spaces in both the pattern and search strings and use indexOf() if that's acceptable (might be a problem if you don't have enough memory to do so).

I don't think a regex would be a good idea, but you could basically make a pattern like:

/f\s*o\s*o\s*b\s*a\s*r/ 

Which basically has optional whitespaces in between every character.

Upvotes: 4

Related Questions