0

How can I get the negative of the result of this regex?

8000[0-9]{12}|4000[0-9]{12}|2000[0-9]{11}

I just want to modify the regex to get the negative.

Example with this sample:

200045646587982  
8000046678465132  
8000078526654112  
4000846464256741  
4000875465123111  
8318548479844423  
8020489065458054  

If I execute the current regex, I get that result:

200045646587982  
8000046678465132  
8000078526654112  
4000846464256741  
4000875465123111  

I want the regex returns the reverse:

8318548479844423  
8020489065458054  
2
  • 3
    By negative do you mean inverse? Commented Nov 8, 2012 at 16:09
  • 1
    So you want to match, when this pattern doesn't? Commented Nov 8, 2012 at 16:17

3 Answers 3

2

it depends on what tools you can use.

I would take my input and use the "positive" regexp to replace the matching lines with empty strings and then getting rid of them.

For instance, if your input is a file and you are working in an Unix environment:

cat input.txt | sed s/my-positive-regexp//g

would replace the matching strings with empty strings.

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

Comments

0

View my answer here: https://stackoverflow.com/a/12139118/1548853

Even though the answer is not directed towards you entirely, the same principle applies.

Comments

0

I think this is simpler than inverting / negating the pattern.

    if (!Regex.IsMatch("input", "pattern")) 
    {
    }

2 Comments

I know how to do that in c# and it is easy but I need to modify the regex expression to get the reverse of my current result.
No you don't "need to". You could just read the data line by line.

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.