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) – Mathletics 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
  • 7,673
  • 5
  • 36
  • 48
0

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

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

Live Demo

hwnd
  • 67,942
  • 4
  • 86
  • 123
0

This seems to work:

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

See live demo

Bohemian
  • 389,931
  • 88
  • 552
  • 692