user31735
user31735

Reputation: 113

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.

Upvotes: 0

Views: 851

Answers (2)

dnoeth
dnoeth

Reputation: 60472

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

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269933

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_, '^".*[^"]$')

Upvotes: 1

Related Questions