Home > Enterprise >  How to get specific character in complicated condition
How to get specific character in complicated condition

Time:12-08

I have like following columns.I'd like to get letters after login_name

test_id:taaotai,priority:Primary,login_name:[person1]

I'd like to get person1 from above column.

If someone has opinion, please let me know

CodePudding user response:

You can use substring with a regex:

select substring(login_name from 'login_name:\[(.*)\]')
from your_table

CodePudding user response:

Regexp search will do the job.

select (regexp_matches(
  'test_id:taaotai,priority:Primary,login_name:[person1] and whatever else', 
  '\mlogin_name:\s*\[(. )\]')
)[1];

-- person1
  • Related