Hi All,
Need help in generating Regex expression for the below string.
I want to use a regular expression in an if condition to check if the current string is matching that syntax or not.
String is in form of Service Now ChangeRequest Number eg → CHG1234567, CHG3247586, CHG5768479 etc. Also, it should be not case sensitive.
the digits post CHG can be n number of digits like 8,9,10 etc. Example - CHG12345678, CHG123456789 etc
Any help is appreciated.
Thanks!!
ppr
(Peter)
November 14, 2022, 11:49am
2
pattern could look like this:
CHG\d{7}\b
for this we are using the CaseInsensitive regex option
Hi @Dhruvi_Arumugam check this regex pattern: (?:chg\d{1,7})
Hi @ppr
Thanks for the quick reply
In the expression you provided I can see you have use d{7} but if the digits increase than 7 will in that case it will work?
The expression should ideally check for this format starting with “CHG” and then having any n number of digits that makes a valid change request.
ppr:
d{7}
Thanks
ppr
(Peter)
November 14, 2022, 11:55am
5
we can use for this CHG\d+\b
Kindly note:
How can we use this in If condition?
Thanks @Tapan_Behera1
The number of digits post CHG is not fixed
Thanks!
ppr
(Peter)
November 14, 2022, 11:59am
8
This CheatSheet introduces the basic use of regex functions. With further examples also special cases are presented.
Introduction
From the namespace System.Text.RegularExpressions following methods are offered:
Regex.Match
Regex.Matches
Regex.isMatch
Regex.Replace
Regex.Split
A simple usage for example would look like this:
[grafik]
Recommendation:
add System.Text.RegularExpressions to the imports:
[grafik]
it allows to use the shortened statement, as the namespace part can be ommited…
System.Text.RegularExpressions.Regex.isMatch("YourString","CHG\d+\b",RegexOptions.IgnoreCase)
Gokul001
(Gokul Balaji)
November 14, 2022, 11:59am
9
HI @Dhruvi_Arumugam
You can Try with this Regex Expression in If activity
System.Text.RegularExpressions.Regex.IsMatch(YourString,"CHG\d*\b")
Regards
Gokul
@Dhruvi_Arumugam Okay then just update it to (?:chg\d*)
if you want to match at least one number or more then in that case you can change (*) to (+)
Gokul001
(Gokul Balaji)
November 14, 2022, 12:01pm
11
Check out the screenshot @Dhruvi_Arumugam
ppr
(Peter)
November 14, 2022, 12:05pm
12
to complete the series:
as *
means 0 or unlimited it will also match CHG without numbers
2 Likes
Thanks a lot @ppr @Gokul001 @Tapan_Behera1 for your valuable responses !
system
(system)
Closed
November 17, 2022, 12:21pm
14
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.