Regex to extract text before keyword and include the keyword

Hello,

Please help with regex code to extract the text before a keyword and include the keyword in the output.

Sample input string:
This is a test.ca ABC123

Fixed keyword: “.ca”

Expected output: test.ca

I tried this: \b.*(?<=).ca
But it’s extracting everything from the start of the line until the keyword.

Thanks

I recommend to get familiar with this website https://regexr.com/

Hi,

Can you try the following pattern?

\S*\.ca

image

Regards,

1 Like

HI @6027ae06be5a67a04d29acc18

How about this pattern?

\S*\Wca

image

1 Like

Thank you, this works!

1 Like

Thanks for the suggestion. The period before “ca” is important to differentiate the keyword from other strings that could contain “ca”. This code doesnt work when I tried \S*\W.ca

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.