简体   繁体   中英

Regex for string not ending with given suffix in teradata query

I am trying to fetch the rows from database where it start with a quote sign and do not end with quote sign. I have rows as follows in the Name column,

"TEXT
"TEXT"
"TEST
"TEST"

Desired output from select query,

"TEXT
"TEST

SQL query,

SELECT * FROM db.supplier where  regexp_instr(Name_ ,'^[\"][\w-_.]+(?<!")') = 1;

I know the regex should be ending with $ to mark the end but it also didn't worked. Any suggestion is much appreciated.

How about using like ?

where Name_ like '"%' and Name_ not like '%"'

That seems simple enough. You could also use regexp_similar() :

where regexp_similar(Name_, '^".*[^"]$')

Why are you using a negative lookbehind? This will return any values which start, but don't end with a double quote:

where regexp_similar(Name_ ,'".+[^"]') = 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM