Regex pattern clarification

Hi Everyone,

image

In the above string, i want the string of 8 digits highlighted without any hyphen. Could you please help me on this?

Thanks,
Ulaga

Is there always an F in front of it? In that case: F\d{7}

Here \d means any digit, and {7} means ‘repeat 7 times’. So this will match any part of the string where there’s a capital F followed by 7 digits.

Thank you. Any alphabet will be in the beginning and the hyphen also could be anywhere in the string

JIFLOPIO (I want to retrieve only this string without any hyphen)
-IFOPFLW

Hello @Boopathi

Try this
Dim match As Match = Regex.Match(input, “CN=.*([a-zA-Z1-9]{8}),”, RegexOptions.IgnoreCase)

@Boopathi Have a look at below regex link it matches alphabets followed by seven digits

@Boopathi please be clearer as to what you want exactly. I see that your output could be an alphabet followed by 8 (BTW I see only 6) digits with a possibility of a hyphen anywhere in between the characters. But do be clear about what your desired output is. Do you just want the digits form such strings? Or do you want to extract any such strings where the above conditions hold true?

Say your input is this: F9078-74.

What is your desired output?

1 Like

This pattern should match any occurence of 8 characters without hyphen anywhere in the string.

(?<!-)\w{8}(?!-)

1 Like

I’m not sure, but I think this is exactly what you’re looking for:

“[a-zA-Z][\d-]{7}”

Use the above regex string in the “matches” activity of UiPath. The result will give you strings with 8 characters that start with an alphabet, has digits and the hyphen could be anywhere. Now if you don’t want these matches to have hyphens, just replace the hyphen (-) in the matched strings with an empty string (“”).

3 Likes

Hey @Boopathi

Will you clarify ? 8 digits? excluding Alphabet ?
and 8 digits count with Hyphen count or without ? :slight_smile:

Regards…!!
Aksh

Thank you everyone. To be clear I want 8 characters without the character [-]

  1. GHRY-009
  2. JHYUOPR5
  3. 0987-09R
  4. OPIUKJ89 - I want to retrieve only this 8 characters or word

Thanks,
Ulaga

@evangemert. Thank you. It works as expected.

1 Like

Hey @Boopathi

Try this:- [\w-]{8}$

Regards…!!
Aksh

Apparently, he wasn’t looking for this. He meant he needed only those strings with eight characters which do NOT have a hyphen in it.

@siddharth
Well what i asked before it was related with that and even if she wants want u then it is a simple change -

@Boopathi
[\w]{8}$

Regards…!!
Aksh

1 Like

Hi @aksh1yadav and @siddharth. Thank you for your suggestions and got the solution.

1 Like

@dkollyns Thank you. It works as expected

1 Like