Home » SQL & PL/SQL » SQL & PL/SQL » Regex Help
Regex Help [message #683397] Thu, 07 January 2021 12:25 Go to next message
ssmith001
Messages: 37
Registered: August 2018
Member
I've very new to writing regex and am struggling to write an expression to remove the text from the beginning, up to the name of the title.

[LZ3oXoFsOJo] Title A
[hGYM1XZrKyg] Tile B
[5SYJN0W] Tile C

All I want to return is
Title A
Title B
Title C
Re: Regex Help [message #683398 is a reply to message #683397] Thu, 07 January 2021 12:30 Go to previous messageGo to next message
Littlefoot
Messages: 21806
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
For such a simple problem, you'd perhaps rather use SUBSTR + INSTR combination (as showed in RESULT2).

Anyway, see if this helps. Query you might be interested in begins at line #6:

SQL> with test (col) as
  2    (select '[LZ3oXoFsOJo] Title A' from dual union all
  3     select '[hGYM1XZrKyg] Tile B'  from dual union all
  4     select '[5SYJN0W] Tile C'      from dual
  5    )
  6  select col,
  7         regexp_replace(col, '\[.+\] ', '') result1,
  8         --
  9         substr(col, instr(col, ']') + 2) result2
 10  from test;

COL                   RESULT1    RESULT2
--------------------- ---------- ----------
[LZ3oXoFsOJo] Title A Title A    Title A
[hGYM1XZrKyg] Tile B  Tile B     Tile B
[5SYJN0W] Tile C      Tile C     Tile C

SQL>
Re: Regex Help [message #683399 is a reply to message #683398] Thu, 07 January 2021 12:56 Go to previous messageGo to next message
ssmith001
Messages: 37
Registered: August 2018
Member
perfect, thanks!
Re: Regex Help [message #683507 is a reply to message #683399] Mon, 25 January 2021 05:16 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
If you can use the substr/instr. It is faster then user a regular expression. if it's only a few rows then use either. If your scanning millions of rows then use the substr/instr
Previous Topic: Weird PL/SQL behavior with SQL statement containing a function in WITH clause
Next Topic: print "+" when using to_char
Goto Forum:
  


Current Time: Thu Mar 28 15:31:42 CDT 2024