开发者

Regex help for NOT expression

I need a regular expression in java that does the following,

Match a pattern that is NOT the following

  • An optional negative sign ( '-' ) Followed by
  • One to four numbers Followed by
  • An optional dot cha开发者_如何转开发racter 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

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

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]+))

This seems to match your examples, but I'm still not sure what you're trying to accomplish with this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜