I want to verify if the string began with name(followed by 3 digits) and ends with state.
My code did this
Actual Output: NOT, NOT, YES, YES, YES, YES, NOT.
Expected Output: NOT, NOT, NOT, NOT, NOT, YES, NOT
CREATE TABLE yourtable
("f1" varchar(19))
;
INSERT INTO yourtable
("f1")
VALUES
('name123/state/LA'),
('name123/state/LA/X1'),
('name1/state/'),
('nameabcccc/state/'),
('name3444/state/'),
('name444/state/'),
('name1/state/LA')
;
SELECT f1,
CASE when trim(f1) ~ '^name[^/]*/state\/$' then 'YES' ELSE 'NOT' END col2
FROM yourtable
name344sdfdfd/state/?