0

I use this regex for extract email:

regexp_replace(xxx, '.*=([A-Za-z0-9._%-]*@[A-Za-z0-9._%-]*\.[A-Za-z]{2,4}).*','\1')
regexp_like(xxx,'=+[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,4}')

I can extract string like this:

select regexp_replace('/AAA-SSS-CCC?User=testmail@mail.com?Id=12323424','.*=([A-Za-z0-9._%-]*@[A-Za-z0-9._%-]*\.[A-Za-z]{2,4}).*','\1')

Output: testmail@mail.com

But I can't extract string like this:

select regexp_replace('/AAA/SSS/CCC/testmail@mail.com?Id=12323424','.*=([A-Za-z0-9._%-]*@[A-Za-z0-9._%-]*\.[A-Za-z]{2,4}).*','\1')

Output: /AAA/SSS/CCC/testmail@mail.com?Id=12323424

How can I do that?

Thanks.

onur
  • 5,647
  • 3
  • 23
  • 46

1 Answers1

0

Try This. I have modified the pattern to be matched before @ appears. It matches one or more occurrence of any character other than @, which matches / .

SELECT REGEXP_REPLACE (
          '/AAA/SSS/CCC/testmail@mail.com?Id=12323424',
          '^([^@]+)@[A-Za-z0-9._%-]*\.[A-Za-z]{2,4}.*',
          '\1')
  FROM DUAL;
Kaushik Nayak
  • 30,772
  • 5
  • 32
  • 45