How to apply OR to regex

Hi all
I want to apply OR for regex…
Can you look into this

Input:
Name="[Apple]"
Name=“Orange”

Expected Output:
Apple
Orange

I tried using (?<=Name="[).(?=]")|(?<=Name=").(?=") but it is giving
[Apple]
Orange

@Kavya_Mamidishetti2

grafik
and refer to groups:

grafik

Pattern: (?<=Name=")\[?(.*?)\]?(?=")

@ppr Thanks for the response I tried assigning to a variable of list type it is throwing me error.Can you look into it

Assign value-System.Text.RegularExpressions.Regex.Matches(v_Notepad,"(?<=Name=")[?(.*?)]?(?=")").Cast(Of Match).Select(Function(m) m.Value.ToString).ToList

will ha ve alook soon on it.
Kindly note:You are not using groups in your current statement

ohh okay.I am new to Regular expressions.Will look into groups.

Ensure Following:
grafik

So we can ommit the namespace begin

Pattern (?<=Name=")\[?(.*?)\]?(?=") does contain " we have to handle extra within the pattern string assignment as following:
"(?<=Name="")\[?(.*?)\]?(?="")"
grafik

Here we go:

Regex.Matches(strText,strPattern).Cast(Of Match).Select(Function (m) m.Groups(1).toString).toList

with immediate box we can fast prototype and check.

Also have a look here:

1 Like

Thanks. It is working fine as per my request. When I try to implement it on my text file it is not working. My text file has so many lines.Here is the sample one

<y:FruitName=‘ForestApple’ category.fruit=‘Apple_1’ Name=’[Apple]’ fruit=’[v_Fruit]’ />

<z:FruitName=‘ForestBanana’ category.fruit=‘Banana_3’ Name=‘Banana’ fruit=‘all’ />

its not about the lines, it is about the different character.

You requested for Name=" ← "
The screenshot shows Name=’ ← ’

So just adopt the pattern and test it again

@ppr If you look into regex i have already replaced " " with ’ '.

Yes but with double ’
grafik
grafik

We do not need to Unescape / Quote in String the ’ char