Search code examples
regexalteryx

Regular expression using positive lookbehind not working in Alteryx


I am trying to match a string the 2nd word after "Vores ref.:" using positive lookbehind. It works in online testers like https://regexr.com/, but my tool Alteryx dont allow quantifiers like + in a lookbehind.

"ABC This is an example Vores ref.: 23244-2234 LW782837673 Test 2324324"

(?<=Vores\sref.:\s\d+-\d+\s+)\w+ is correctly matching the LW78283767, on regexr.com but not in Alteryx.

How can I rewrite the lookahead expression by using quantifiers but still get what I want?


Solution

  • You can use a replacement approach here using

    .*?\bVores\s+ref\.:\s+\d+-\d+\s+(\w+).*
    

    Replace with $1.

    See the regex demo.

    Details:

    • .*? - any 0+ chars other than line break chars, as few as possible
    • \bVores - whole word Vores
    • \s+ - one or more whitespaces
    • ref\.: - ref.: substring
    • \s+ - one or more whitespaces
    • \d+-\d+ - one or more digits, - and one or more digits
    • \s+ - one or more whitespaces
    • (\w+) - Capturing group 1: one or more word chars.
    • .* - any 0+ chars other than line break chars, as many as possible.