-1

I am trying to extract everything from my list of strings after the last underscore, after MOB_ in big query.

See example below:

STRING:

Topshop_AW19_Pro_MOB_competitors(mid price point)custom_affinity

DESIRED OUTPUT:

competitors(mid price point)custom_affinity
Georgy
  • 378
  • 1
  • 11
Suhayb Dar
  • 21
  • 6

2 Answers2

0

Here is one of the possible solutions :

SELECT SUBSTRING(your_field, LOCATE('MOB_',your_field)+4)
FROM your_table;

or with regexp

SELECT REGEXP_SUBSTR(your_field,'(?<=MOB_).*$') 
FROM your_table

EDIT with oracle :

SELECT substr(regexp_substr(your_field,'MOB_(.*)'),5) "result" FROM your_table;

if you don't want to use substr http://sqlfiddle.com/#!4/a4021/20 :

SELECT regexp_substr(your_field,'MOB_(.*)', 1, 1, NULL, 1) "result" FROM your_table;

Edit 2 with oracle : See more examples here http://sqlfiddle.com/#!4/a4021/31 One with regexp_replace and one with instr (= find in oracle).

Gosfly
  • 1,162
  • 7
  • 14
0

This seems direct to the point:

RIGHT(stuff, RIGHT_FIND(stuff, 'MOB_'))

Interesting the documentation seems to have some errors:

https://cloud.google.com/dataprep/docs/html/RIGHT-Function_57344732

https://cloud.google.com/dataprep/docs/html/RIGHTFIND-Function_118228807

Hogan
  • 63,843
  • 10
  • 75
  • 106