REGEX - How do I search for expressions that DO NOT contain a specific part?

Asked

Viewed 88 times

-1

I’m working with PL/SQL.

Through REGEX, how do I find all expressions that are different from:

 <cod_orgao_destino>9577</cod_orgao_destino>

Thank you!

  • 2

    php, javascript, python, java or c#? If this is an XML it would be better to work with a DOM LIB (Object Document).

  • I am working with PL/SQL.

  • With Xpath it is possible, but I have no experience with PL/SQL, but possibly something close to this: https://stackoverflow.com/a/19584903/1518921 ... I believe Xpath is //cod_orgao_destinorow[not(text() = '9577')] (the // is at any level, but I believe that if you have a specific structure it would be something like /foo/bar/baz[...]) ... I haven’t used xpath in a while, but if it doesn’t work try this: /foo/bar/baz[not(contains(cod_orgao_destino, '9677'))]

  • Related: https://answall.com/q/241285/64969

  • As @Guilhermenascimento commented, if it is to work with xml it is much better to use a specific library for this feature, remembering that Oracle provides Xmltype and many read and write methods, which would make your life much easier.

  • The search will not be done in an XML. I want to do this search in a string that contains this structure. My question is about how to do this scan using the same REGEX.

  • See if the following suggestion would serve, use a "not REGEXP_LIKE(Text , Your expression, 'i')"

  • It depends a lot more on what you want to take than what you don’t want to take, if it’s for example to take something similar to <cod_orgao_destino>VALOR</cod_orgao_destino>, but that the value is different from 9577 then it is possible to give an answer, but if the goal is to take something else besides that only you explain better with an example of a full value than it has (format) and what you want to take in this syntax your specific.

Show 3 more comments

1 answer

0

It is possible thanks to Negative Lookahead (n know how to translate this) "(?! abc)"!

You can get that by using that expression:

^((?!<cod_orgao_destino>9577<\/cod_orgao_destino>).)*$

I found a place explaining in detail: Here

  • The regex is correct but the application is in pl/sql

Browser other questions tagged

You are not signed in. Login or sign up in order to post.