how to negate any regular expression in Java

I have a regular expression which I want to negate, e.g. /(.{0,4}) which String.matches returns the following "/1234" true "/12" true "/" true "" false "1234" false "/12345" false Is there a way to negate (using regx only) to the above so that the results are: "/1234" false "/12" false "/" false "" true "1234" true "/12345" true I'm looking for a general solution that would work for any regx without re-writing the whole regex. I have looked at the following https://stackoverflow.com/questions/2637675/how-to-negate-the-whole-regex using (?! pattern), but that doesn't seem to work for me. The following regx (?!/(.{0,4})) returns the following: "/1234" false "/12" false "/" false "" true "1234" false "/12345" false which is not what I want. Any help would be appreciated.
Couldn't you just match and negate whether or not it matched? That's the general-purpose solution for any regex w/o rewriting the regex.

以上就是how to negate any regular expression in Java的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏