Regex pattern to remove special character

Hello,

I need to remove the special character from the string.
WQ#1234567
WQ 1234567
WQ/1234567
WQ-12345678
Q#1234567
Q 1234567
Q/1234567
Q-12345678

The actual output should be like wq1234567 and q1234567
Wq followed by 7digit and q followed by 7 digit.

Please help

Regex.Replace(input, “(?i)(WQ|Q)[#\s/-]*(\d{7})”, Function(m) m.Groups(1).Value.ToLower() & m.Groups(2).Value)

Hey @sharu_priya try this code

as you can see in the image it will remove special character

System.Text.RegularExpressions.Regex.Replace( yourValue, “[^a-zA-Z0-9]”, “”)

cheers happy automation

Hey @sharu_priya
Try this approach:
BlankProcess13.zip (3.0 KB)




Assign activity:
strCleansed =

System.Text.RegularExpressions.Regex.Replace(yourStringVar.Trim(), "(?<=^W?Q)[#\s\/\-](?=\d{7})", "")

Main.xaml (7.7 KB)

n
Use above sequence.
Don’t forget to Import System.Text.RegularExpression namespace

will try and let you know… Thanks much

@adi.mehare @pikorpa @singh_sumit @ppr

Thank you so much for all your valuable comments.

I need this in a single regular expression because one of all this formats will be there in the mail.

So bot should extract Wq1234567… format can any one of these and moreover i will be placing this regex in asset.

To be short, all this format should work in one regular expression.

(?i)\b(WQ|Q)[-\s]?\d{7,8}\b- this pattern extracts all except (- and / i.e WQ-12345678, WQ/1234567)

Please help

this should take care of your all formats, you don’t need any different formates

@sharu_priya basically this regex is used to remove special character from your value so if the value changed it still working for you. so try it on with multiple values . this should take care of all formats.

cheers Happy Automation

Hey @sharu_priya
Please check this solution:
BlankProcess13 (2).zip (2.6 KB)

@singh_sumit @pikorpa @adi.mehare @ppr

The requirement is little different:

I need to get only WQ3153682 from the below text.

" Freight Pickup: 232613 LTL Less-Than-Truckload (Dry Van) from Langley Township, BC to Sumner, WA Caller: Shipper: Consignee: Caller is the: Shipper Billing is: Prepaid (Shipper Will Pay) Payment by: CSA Shipping Account Company Name: Panefri North America Contact Name: ABC Phone: 0000000000 Associated CSA Quote Number: WQ3153682 Your Email: orders@panefri.commailto:orders@ABC.com Confirm Email: orders@ABC.com Company Name: ABC Contact Name:ABC”

This is the mail body.

So in any of the mail body wq… contains means i need to extract only that.

so that wq will be in different formats like i mentioned in the query.

Little tricky so please help me

I am using find matching pattern activities… in that text in search property this string will be there which is extracted from mail body.

So i have to give that pattern which extracts wq…

Does the mail body always contain 'Quote Number: ’ followed by the WQ/Q extraction you need? Then you could just use (?<=Quote Number:\s)[A-Za-z0-9]+ I think.

no… if the wq contains any special char… it should not take that special charactrs.

it should fetch only wq or q followed by 7 or 8 digits

Yes, sorry you’re right. I’m not sure if there’s a regex way to do this. Maybe you need a extra step to remove the special characters. Hopefully someone else has the solution for you.

@sharu_priya
we suggest that you have a closer look at regex
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

And also on doing experiments within the immediate panel
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

So you can explore and tests directly regex statements e.g. crafted with the help of an online editor like: https://regex101.com/

so you can check on the following strategies:

  • matching (strict)
  • match all variations, then replace inner unneeded chars

Pattern was given before

and was addressing the origin:

i invoked the below code…it says no match found though match is found

Invoke code:
’ Input String
Dim inputStri As String = “Freight Pickup: 232613 LTL Less-Than-Truckload (Dry Van) from Langley Township, BC to Sumner, WA Associated CSA Quote Number: Q315362 Your Email: orders@panefri.com”

’ Regex Pattern
Dim patte As String = “(?<=^W?Q)#\s/-”

’ Perform Match
Dim matchResult As String = “”
Dim match As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(inputStri, patte)

’ Check if a match is found
If match.Success Then
’ Combine “WQ” or “Q” with the digits
matchResult = match.Groups(1).Value.ToLower() & match.Groups(2).Value
Else
matchResult = “No match found”
End If

’ Assign the result back to UiPath variable
result = matchResult

I need to complete this by today…Please help

not needed, can be done without blackboxing

when i tried your pattern… it gives the actual input

"(\bW?Q)([\D]?)(\d+\b)\b"

will work also on the variation:

And will handle not found Match

For sure it can be adapted and modified if it is needed

Also have a look here:
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

1 Like