开发者

Regex in java and ignoring white spaces

开发者 https://www.devze.com 2023-01-17 16:24 出处:网络
I want to write a regex to match on a string and ignore white spaces.For examp开发者_JS百科le, a search for \'foobar\' would match on \'foo bar\'. You can strip the spaces in both the pattern and sear

I want to write a regex to match on a string and ignore white spaces. For examp开发者_JS百科le, a search for 'foobar' would match on 'foo bar'.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消