How to use \n in regex with Uipath Matches activity

I created below regex function in regex website.

\S.+\n(?=(~PART#)|( PART#)|(PART#)|\n(PART#))

In Regex website it is working fine.

But in Uipath i used in Matches activity

In Matches activity \n(PART#) is not working.

I think \n is not working

try \r?\n

\S.+\r?\n(?=(~PART#)|( PART#)|(PART#)|\n(PART#))

As Windows comes along the carriage return and line feed for the line break

Also check for the Multiline option.

Maybe you can share some sample data with us along with a description of the expected output

1 Like

Hi @BNK , I hope you are doing well.
For your problem you can try:

  1. \r= CR (Carriage Return) → Used as a new line character in Mac OS before X
  2. \n = LF (Line Feed) → Used as a new line character in Unix/Mac OS X
  3. \r\n = CR + LF → Used as a new line character in Windows

I hope any 1 of the above 3 will get you your desired solution.

Thanks & Regards,
Shubham Dutta

1 Like

Hi @BNK

As per @ppr’s reply, some Samples, expected Output and information on the Pattern will greatly assist with a reliable Regex Pattern.

In the meantime can you try this pattern:

\S.+[\n\r]+(?=(~PART#)|( PART#)|(PART#)|[\n\r]+(PART#))

Hopefully this helps :blush:

Cheers

Steve

1 Like

@ppr

I tried all the above solution it is working fine in regex website but it is not working in Matches activity(I am not using any flages in regex website)

Samples:

PARTS

PART#

just provide the sample text as text file or by formated text usingg </> from editor
share with us, what is achieved

in general you should handle \n as \r?\n

But maybe already set by the tool

m - Multiline option

Hi @BNK

As per @ppr said can you try multiline flag?

I had a small typo on the Regex pattern (on mobile). Can you try:
\S.+[\n\r]+(?=(~PART#)|( PART#)|(PART#)|[\n\r]+(PART#))

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