0

so i want the regex match this type of elements, this regex is created in javascript.

I assume in mongo you need \\ to escape instead of one

element: toto|titi|tata|tete

  • if my value is tete or titi or tata or tete it return false

  • if my value to or ze or we it return true

  • toto|titi as value does not matter because i have a regex removing specials characters from value (it will become tototiti)

atm i used "(^|\|)" + value + "(\||$)" to get the opposite - when my value is tete or titi or tata or tete it return true

  • when my value to or ze or we it return false

i tried

  • "(^|\|)(?!" + value + ")(\||$)" didn't work

  • "(^|\|)(?!" + value + ").*(\||$)" didn't work

I have no more idea, someone would have one ?

V.pique
  • 71
  • 4
  • Could you clarify what *does not matter about return* means? Also, try `value + "\\B|\\B" + value`, or maybe `value + "[^|\\s]|[^|\\s]" + value` – Wiktor Stribiżew Aug 08 '16 at 14:22
  • when you are testing the regex true when it match, false when it does not match – V.pique Aug 08 '16 at 14:27
  • 1
    Then, I guess, you also need to [escape](http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript) the `value`. – Wiktor Stribiżew Aug 08 '16 at 14:31
  • yeah this is true i will edit the post (i already have a regex removing special characters before) – V.pique Aug 08 '16 at 14:35
  • If you're getting the exact opposite of what you want, then why not just use actual JS to invert the Boolean? `!true` becomes `false` and `!false` becomes `true` – Laurel Aug 08 '16 at 19:45
  • my regex is used by mongo so it doesn't look like possible to do that – V.pique Aug 09 '16 at 07:44

0 Answers0