0

I have following regular expression in c# (ship|sub)(?<!^(shipment|subway)$)

which is used to check if the given data contains ship or sub when the data is not shipment or subway.

I want to write the same expression in java script. I tried several options with javascript negetive look behind.. But they are not serving my purpose: for an example: when i give shipment to the regular expression, it should not return ship(as i am excluding shipment in regular expression) .. however, when i give membership, it should give ship and match result true.

Could any one of you please help me .

3
  • rearrange your post will be help everyone that read your post Commented Jan 28, 2013 at 14:16
  • 1
    3 people voted to close this question, presumably because 90% of the question was missing, but didn't try clicking "edit" to see if something went awry. The unescaped < in the user's code turned out to hide most of the question. Commented Jan 28, 2013 at 14:18
  • javascript regex parser does not support negative lookbehind. see this question Commented Jan 28, 2013 at 14:18

1 Answer 1

1

Your regular expression should not have worked in .NET, either. Once you match "ship" or "sub", the negative lookbehind assertion would always be true: you matched "ship" or "sub", so the previous characters could never be "ment" or "bway", thus passing the assertion always. Instead, you must have meant:

\b(ship(?!ment)|sub(?!way))\b

This should work in Javascript as well, since it's only using negative lookahead assertions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.