0

I'm trying to select commas without numbers of 4 digits or the word "id" before, I tried with this:

   ( ? < ! [ \ d { 5 } | id ] ) ,

The problem

for example, if input string is "1999," that comma is not selected, I don't understand why.

2
  • 1
    It's not clear what you want to achieve. Commented Jan 11, 2013 at 14:53
  • 1
    Please provide examples of what do you want. Commented Jan 11, 2013 at 14:55

2 Answers 2

3

Try this pattern:

(?<!\d{5}|id),

Your pattern, (?<![\d{5}|id]), is looking for a comma that is not after a digit, {, }, |, i, or d - They should not be in a charterer class: []. If anything, (?<![\d]{5}|id), will also work, but is redundant.

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

Comments

1

First of all, unless you're using the /x flag, each space will attempt to match a space. So take those out.

Second, you're using [...] presumably to group an alternation (|) but square brackets actually indicate a character class, i.e. [\d{5}|id] is equivalent to [id5{}|] and matches any one of those characters, but not more. What you mean is this:

(?<!\d{5}|id),

The final problem might be that many implementations of regex (you haven't specified which you're using) don't support variable-width lookbehind assertions. So, you may need to do something like:

(?<!\d{5}|...id),

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.