-1

I've been trying to make a regex match that will match against CPU instructions like:

and val1, val2
sub val1, val2

How can I make a regex that can perform a wildcard in place of both of these values BUT, the two values cannot be the same?

and ...\, ...
sub ...\, ...

But where the first ... != the second ...

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Sasuke
  • 13
  • 5
  • 2
    What language/tool are you using? From the [regex tag info](https://stackoverflow.com/tags/regex/info): "Since regular expressions are not fully standardized, all questions with this tag should also include a tag specifying the applicable programming language or tool." – Toto Jun 13 '20 at 17:28
  • I'm not using any particular programming language, I'm just using the terminal command grep – Sasuke Jun 13 '20 at 17:44
  • 1
    @Sasuke added the [tag:grep] tag for ya :) – wjandrea Jun 13 '20 at 18:06
  • [This](https://unix.stackexchange.com/a/497679/117037) might be useful. Otherwise I think grep is too limited to do this properly. I wrote a solution in Python if you're open to it. – wjandrea Jun 13 '20 at 18:21
  • Yeah, I wasn't too sure whether grep was capable of doing it. I thought grep might work just to pipe into but python is a good workaround. – Sasuke Jun 13 '20 at 19:16

1 Answers1

0

Using any awk in any shell on every UNIX box:

awk -F'[ ,]+' '($1 ~ /^(and|sub)$/) && ($2 != $3)' file
Ed Morton
  • 188,023
  • 17
  • 78
  • 185