anmita
August 23, 2023, 7:38am
1
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
Yoichi
(Yoichi)
August 23, 2023, 7:41am
3
Hi,
How about the following expression?
System.Text.RegularExpressions.Regex.Match(textfound,"(?<=PName:\s*\W\s*)\w.*").Value
Regards,
anmita
August 23, 2023, 8:09am
4
Thanks for the prompt responses
@Shiva_Nikhil and @Yoichi
Are there any other approach that you could Suggest
Yoichi
(Yoichi)
August 23, 2023, 8:14am
5
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,
anmita
August 23, 2023, 8:29am
6
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
Yoichi
(Yoichi)
August 23, 2023, 8:33am
7
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.
it was matching all the text ANKKK
system
(system)
Closed
August 26, 2023, 9:00am
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.