Regex Issue (Any)

Hi, I am having some issues with the Regex Builder. When I choose quantifier Any (because I want all instances of this pattern), the regex does not work. Does anyone know what the issue is? I need to extract all the numbers from a string that starts with “900” followed by 7 digits. Ex. “9001234567”

Since you’re using Advanced mode, the expression is complex enough for the ‘Any’ modifier to make it confusing.
The ‘*’ asterisk has been simply appended to your pattern when you selected Any.

You can fix this by putting your entire expression in a bracket:
((?=900).\d{9})*

EDIT: Also, you’ll probably need to change the length from {9} to {7} since you said it should match 7 digits after 900.

2 Likes

Hi,

Can you try the following pattern using Matches activity?

"(?<=^|\D)900\d{7}"

Regards,

2 Likes

Edit: You are in the right place with the help of @Yoichi and @RPAForEveryone :wink:

Hi

Explanation of your pattern: Your regex pattern is looking for “900” then searching for any digit (represented by the “.”) then 9 digits (0-9).

Which looks it might be working…so maybe its your input?

Is there any reason you are not using a simpler Regex pattern. Its best to keep it simple :slight_smile: I would recommend the following:

  • 900\d{7}
  • \d{10}
  • (?=900)\d{10}

Please provide a sample, we have the the output from your post, and any information on the pattern you can provide.

3 Likes

Hi, so basically I need to read a string which could look like this:
97841820384056 Inv:9001234567 ClientName
I want to read 9001234567 which should start with 900 and have a fixed length of 10 digits and in some cases may have multiple occurrences like so (location of the string may vary a lot):
77841820384056 Inv:9001234567 9007654321 ClientName

1 Like

Edit: So far the alternative provided by @Yoichi is working. Thanks for the help everyone.

If I change to 7, it doesn’t pick up everything.

Edit: Sorry - {10} for the full string

Hello

Change the {7} to {9} for the full string.

Cheers

Steve

2 Likes

Hi,

You can simply write it as (?=900)\d{10}.
However, it also match the following bold characters 123900123456789. Is it good for you?

If not, i recommend to use (?<=^|\D)900\d{7} as I mentioned, or (?<=^|\D)900\d{7}(?=\D|$)

Regards,

2 Likes

Yes, the one you recommended works better. May I ask what the 2nd one you mentioned will do?

Best way to learn and decode regex:

Hello

Can I recommend this Regex pattern:
\b900\d{7}\b

It will eliminate this problem of “123 9001234567 89”

image

Main.xaml (6.5 KB)

1 Like

Hi,

If there is 12 digits number starting 900, (?<=^|\D)900\d{7} matches as 9001234567 89.
On the other hands, (?<=^|\D)900\d{7}(?=\D|$) doesn’t match.
It matches just 10 digits number as the following
9001234567 : match
90012345678 : not match
9001234567A : match

Edit: @Steven_McKeering pattern is also good. It depends on your requirement which is better, I think,

Regards,

2 Likes

Regex101.com is a great place to start @RPAForEveryone - but I am bias towards my Regex MegaPost to help new users :laughing:

2 Likes

Absolutely! :smiley:

1 Like

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