0

I have looked through the other questions asked on excluding regex, but I was unable to find the answer to my question.

I have the SQL statement

select --(* vendor(microsoft), product(odbc) guid'12345678-1234-1234-1234-123456789012' *)-- from TAB

With regex, I want to find every single character in that string, except

--(* vendor(microsoft), product(odbc)

and

*)--

The vendor and product names (microsoft and odbc) could be anything as well, I still want to exclude it.

I don't care what kind of characters there are, or if the SQL statement is even syntactically correct. The string could look like this, and I still want to find everything, including whitespaces, excluding what I mentioned above:

{Jane           Doe?= --(* vendor(micro1macro2?), product(cdb!o) 123$% --(**) *)-- = ?

So far, I have this expression:

(--\(\* vendor\(.*\), product\(.*?\))|(\*\)--)

Which seems to work in finding what I want to exclude https://regex101.com/r/rMbYHz/204. However, I'm unable to negate it.

Helena
  • 1,041
  • 2
  • 12
  • 24
  • Do not negate, just replace with an empty string. – Wiktor Stribiżew Jun 03 '19 at 08:06
  • I do not want to alter the string, I just want to match it. – Helena Jun 03 '19 at 08:10
  • 1
    You cannot efficiently match parts of a string that do not equal some multicharacter string. It is possible to do with PCRE, but it is not a good idea since the regex may freeze the app. – Wiktor Stribiżew Jun 03 '19 at 08:13
  • 1
    With PCRE you would use eg [`(*SKIP)(*F)`](https://stackoverflow.com/questions/24534782/how-do-skip-or-f-work-on-regex) and match the remaining single characters or use a neg. lookahead at each character for the remaining parts [like your updated demo](https://regex101.com/r/rMbYHz/205) (both are not efficient as Wiktor mentions). – bobble bubble Jun 03 '19 at 09:53

1 Answers1

0

Does replace() do what you want?

select replace(replace(t.col, '--(* vendor(microsoft), product(odbc)', ''
                      ), '*)--', ''
              )
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786