简体   繁体   English

正则表达式帮助表达NOT

[英]Regex help for NOT expression

I need a regular expression in java that does the following, 我需要一个java中的正则表达式来执行以下操作,

Match a pattern that is NOT the following 匹配不是以下的模式

  • An optional negative sign ( '-' ) Followed by 可选的负号(' - ')后跟
  • One to four numbers Followed by 一到四个数字跟着
  • An optional dot character Followed by 可选的点字符后跟
  • one or many zeroes ( If there is a dot ) 一个或多个零(如果有一个点)

(?!-{0,1}\\d{1,4}\\.{0,1}0{1,4})

The behavior is below 行为如下

Expression finds a match for 1 Expression does not find a match for 1.0 表达式找到匹配1表达式找不到1.0的匹配项

when it cones to regex it some times results in a simpler solution if i ask what i need to accomplish as opposed to questions about inner workings. 如果我认为我需要完成什么而不是关于内部工作的问题,那么当它有效地使用正则表达式时会产生一些更简单的解决方案。

In my case 就我而言

I want to catch an decimal number pattern but anything like 1.000 is fine but 1.0001 is not 我想要捕捉一个十进制数字模式,但像1.000这样的东西很好,但1.0001不是

Some examples 一些例子

1           No match
1234        No match
99          No Match
1.000000    No match
123.000000  No Match
-123        No Match

1.01        Match
-1.1        Match
12345566    Match 
^-?\d{1,4}(\.0+)?$

You need to use the program itself to reject input. 您需要使用程序本身来拒绝输入。 Perhaps match valid numbers, then reject anything that matches this, then return. 也许匹配有效数字,然后拒绝与此匹配的任何内容,然后返回。

((-)?(\\d){1,4}+(\\.)?(0)*([1-9]+))

这似乎与你的例子相符,但我仍然不确定你要用这个来完成什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM