Home > Mobile >  Regex to find a word after a specific word and before a specific character
Regex to find a word after a specific word and before a specific character

Time:10-12

I am trying to pull the word that comes after "allignment=" pattern and before the next semi-colon occurance. I only want the first match in the text.

An example text sample:

"Testing all parameters. allignment=gate; Seach all the gateways. allignment=block; Search all the blocks"

Desired output: gate

Note: This is for executing in Impala Database, which does not support look around assertions. I tried regex (?<=allignment=)(\w [^;]) which seems to work in regex testers, but Impala does not support it because it is a look back assertion. Pls help building the required regex.

CodePudding user response:

Impala may not support lookarounds but it allows you to extract matching groups according to this documentation (I hope I'm looking at the right thing).

So you can use

allignment=(\w );

and select the first matching group.

Looks like the syntax would be:

regexp_extract(<text to search>, 'allignment=(\w );', 1)
  • Related