Search code examples
regexregex-groupimpalaregexp-replace

Regex to find a word after a specific word and before a specific character


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.


Solution

  • 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)