-1

I have strings like these:

Jack & Bauer Limited Company Bristol

Streetfood Limited Company München

Brouse with High Jack UnlimiteD Company London

What I want to have is just the company names like:

Jack & Bauer

Streetfood

Brouse with High Jack

So in every case, I have to delete the last 3 words, because the names can be consist a lot of words. I know I have to use regexp, but I dont know how.

Looz
  • 377
  • 2
  • 14

2 Answers2

2

While you can use regular expressions to do this you don't have to. This task can be accomplished using a combination of INSTR and SUBSTR:

SELECT SUBSTR(FIELD1, 1, INSTR(FIELD1, ' ', -1, 3)-1) AS NAME
  FROM TABLE1

SQLFiddle here

Best of luck.

1

Here is one method:

select regexp_replace(str, '( [^ ]+){3}$', '')

Here is a rextester.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786