Regex Pattern issue


I need to create a regular expression for this file.
The yellow color are field names and green color are their respective values.
“(?<=(”+fieldname+“))(.*?(?=\s))”
I was using the above pattern for this. This pattern extract the value till the empty space.
But the issue is for Tesco Recieving Centre ,Depot No you can see the value itself having space so it get only RECIEVEADVICE text only.
I am using the pattern inside the loop . So I can’t able specify the pattern for this field alone.
data.txt (1.0 KB)

Hi,

Can you try the following pattern?

"(?<="+fieldname+").*?(?=\r?\n|$)"

Regards,

1 Like

Hi @agathiyanv

Is the word “RECIEVEADVICE” constant?

Can you try this. The below patterns will catch the word if it exists.

Option #1:
“(?<=(”+fieldname+“))(RECIEVEADVICE\s)*(\S+)”

Option #2: Use if RECIEVEADVICE is not constant but a capital letter word is.
“(?<=(”+fieldname+“))([A-Z]+\s)*(\S+)”

Preview the pattern here. Note: the green captures.

Cheers

Steve

2 Likes

Hello @agathiyanv Try this regex Expression
(?<=“+fieldname+”)\d*|(?<=“+fieldname+”).*

1 Like

Thank you @Steven_McKeering It worked

Thank you @Yoichi for you help

Thank You @Gokul_Jayakumar

Always happy to help :blush:

Cheers

Steve

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