2

I have this regex

^(\d+)/\1$

that matches strings like

1/1
2/2
5/5

I want to get the inverse result of this regex. I browsed the net and stack overflow and found that

^((?!(\d+)/\1.).)*$

should do the trick, but it doesn't.

Could anyone point me into the right direction?

Community
  • 1
  • 1
Tool
  • 12,126
  • 15
  • 70
  • 120
  • 1
    The inverse result? That means **not** matching these kind of strings? – Felix Kling Aug 25 '12 at 15:52
  • 1
    Can't you just test `!match(your_regex)`? Or do you want to match patterns such as `1/2` and `2/3`? – João Silva Aug 25 '12 at 15:52
  • Yeah, Felix - I need strings that don't look like that. @Joao I can't code it, it's a filter inside a datatable. Edit: yes - I need such strings - 1/2 and 2/3 but NOT 2/2 and 5/5 type strings. – Tool Aug 25 '12 at 15:54
  • I have a predictable input: all strings have the format number/number. – Tool Aug 25 '12 at 15:59
  • @Tool: I see, take at look at my answer and see if it suits your needs. Since all your strings have that precise format, it's the exact opposite of the above regex. – João Silva Aug 25 '12 at 16:02

1 Answers1

4
/^(\d+)\/(?!\1$)\d+$/

This will match 2/3 or 1/10, but not 1/1 and 2/2, et cetera. In other words, it will match only when the first part of the fraction is different from the second part.

João Silva
  • 89,303
  • 29
  • 152
  • 158
  • This leaves out 0/10 for me. I need to match 0/10 aswell (condition: number on the left has to be different from the number on the right, and there's no exception to input - they'll always be numbers, so I don't have to worry about that). Edit: it also doesn't show 3/10. – Tool Aug 25 '12 at 16:02