0

I want to match lines with negative numbers or/and decimal numbers with a ^.

-1.2^-2.4  
-12^2.4  
-1^2

but not

1^2
1+2  

I got [\^\D*]{2,} but it is not working

Thanks in advance

  • possible duplicate of [Reference - What does this regex mean?](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Evan Davis Nov 21 '14 at 22:46

3 Answers3

0

Would this work?

/^((-\d+|\.\d+)\^|.+\^(-\d+|\.\d+))/

matches a negative or decimal number followed by ^ or a ^ followed by a negative or decimal number.

sebnukem
  • 8,143
  • 6
  • 38
  • 48
0

It seems to me you are looking for something like the following.

^(?=.*\D{2,})[-.^\d]+$

Live Demo

hwnd
  • 69,796
  • 4
  • 95
  • 132
0

This seems to work:

^-?\d+(\.\d+)?\^-?\d+(\.\d+)?$

See live demo

Bohemian
  • 412,405
  • 93
  • 575
  • 722