How to ' in. REgex expression

Hi All,

I am using a regex expression where I am removing special characters from file name. But I want to include ’ in my file name.I need to include apostrophe but in my current regex expression its removing the apostrophe. It should be JP’s but its making as JPs after regex . I want to include apostrophe so that I get JP’s in my file name .

Regex currently using -“[^\w .-()]”, “”)

for example Original file name JP’s_quarterly_rent_-Nippon_Steel_Kowa_Real_Estate_Co.__Ltd.(Japan)

after applying regex
JPs_quarterly_rent_-_Nippon_Steel_Kowa_Real_Estate_Co.__Ltd

@marina.dutta

Instead of regex use Replace

For example InputString=InputString.Replace(“[”,“”).Replace(“]”,“”).Replace(“(”,“”)

Please provide the inputs and outputs we will help you to get the desired output

Hi @marina.dutta

May I know what is the required output.

@mkankatala

required output should be JP’s_quarterly_rent should include apostrophe. right now after using regex its removing apostrophe and giving output as JPs_quarterly_rent. Below is the Regex I am using . Apostrophe should be there in regex expression. How to include apostrophe in the same regex expression given below.

image

@rlgandu

required output should be JP’s_quarterly_rent should include apostrophe. right now after using regex its replacing apostrophe and giving output as JPs_quarterly_rent

Okay @marina.dutta

Use the below regular expression,

.*(?=_\-)

- Assign -> Input = "JP’s_quarterly_rent_-Nippon_Steel_Kowa_Real_Estate_Co.__Ltd.(Japan)"
- Assign -> Output = System.Text.RegularExpressions.Regex.Match(Input,".*(?=_\-)").Value

Check the below workflow for better understanding,

Hope it helps!!

1 Like

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"[^\u2018\u2019'\w .\[\]\-()]","")

Regards,

1 Like

@marina.dutta

StrOutput=System.Text.RegularExpression.Regex.Match(Input,"[A-Z]+.*(?=\_\-)").Value
1 Like

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