If I want to check all words that contain the substring DEF, would this be the right approach:
^.*[D][E][F].*$
Also is there an easy rule when negating regexes, i.e. modifying the above to identify strings that don't contain DEF
EDIT: I know this doesn't require regexes, but for my pu开发者_StackOverflowrposes it does.
This works too:
^.*DEF.*$
It checks, if the whole String contains the substring "DEF" at least once. But for trivial expressions like this:
str.contains("DEF");
does the same.
Why not just use str.contains("DEF") and !str.contains("DEF")?
You can simply use DEF as your regexp. To identify strings that don't contain it, simply return the strings that don't match the above expression.
加载中,请稍侯......
精彩评论