0

I am trying to use regexp_substr to retrieve string within [!< & >!]. I have below statement but it returned ' To test with regexp_substr.>!]'. How can I exclude >!] and return just the string?

select regexp_substr('[!< To test with regexp_substr.>!]','[^[!<]+>!]') from dual

1 Answers1

0

This method groups everything that is between your start and end character sequences (assuming at least 1 character will be there), then returns just that group of characters. The square brackets need to be escaped so the regex engine does not think you are referring to a character class. Note your example has a space in front of the first letter, which is preserved in the output:

select regexp_substr('[!< To test with regexp_substr.>!]','\[!<(.+)>!\]', 1, 1, 'i', 1) from dual;


STRING_EXAMPLE              
----------------------------
 To test with regexp_substr.
Gary_W
  • 9,933
  • 1
  • 22
  • 40