Define Condition Regex

Hello Team,

How can we provide Or Condition in Regex

Example : PName may be defined in Below Format in WebSite

            PName : ANKKK
            PName- ANKKK
            Pname= ANKKK

Have tried to use in Below Format with Or but that is not working when we try using OR Condition

System.Text.RegularExpressions.Regex.Match(textfound,“(?<=PName:\s).”).Value Or
Or System.Text.RegularExpressions.Regex.Match(textfound,“(?<=PName-\s).
”).Value Or System.Text.RegularExpressions.Regex.Match(textfound,“(?<=PName=\s).*”).Value

Thanks Team in advance

@anmita

try with | pipe symbol not with or

System.Text.RegularExpressions.Regex.Match(textfound,“(?<=PName:\s).”)|(?<=PName=\s)").Value

Hope this helps

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Match(textfound,"(?<=PName:\s*\W\s*)\w.*").Value

Regards,

Thanks for the prompt responses

@Shiva_Nikhil and @Yoichi

Are there any other approach that you could Suggest

Hi,

If you need to check whether the target exists in the page, the following will work.

m = System.Text.RegularExpressions.Regex.Match(textfound,"(?<=PName:\s*\W\s*)\w.*")

Then check m.Success

Or if the above doesn’t work for you, can you elaborate your requirement?

Regards,

Hii @Yoichi

Text that is extracted can contain PName in any one of the below format

Example
1) PName: ANKKK
2) PName- ANKKK
3) Pname= ANKKK

HI,

I had a mistake regarding the above expression.

How about the following?

m=System.Text.RegularExpressions.Regex.Match(textfound,"(?<=PName[-:=]\s*)\w.*")

Then check m.Success

m.Value returns matched content.

Regards,

@anmita

System.text.regularexpression.regex.match(input,(?<=PName:\s).”)|(?<=Pname=\s)").Value

You can make with pipe symbol and try

@anmita How About this?
(?<=[A-Za-z]+[\-:=]\s+)[A-Za-z]+

Hi @anmita

can you try with this it may help you.

image

it was matching all the text ANKKK

image

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