Regex: Extract all number or dashes after text

Hi

For confidential reasons, I can’t show the exact text.

EG1
Revenue as of Mar 19 12200
Ans: 12200

EG2
Revenue as of end of quarter 12200
Ans: 12200

The problem is that sometimes there are date with number before the number I want to extract.

I tried the below. But for Eg1, it always extract from 20. Is this the correct way

(\s\w{3}\s\d{2}){0,1}

to represent 'Mar 19"? I used {0,1} be’cos only sometimes is the date present. Thank you

Trim(System.Text.RegularExpressions.Regex.Match(item,"(?<=Revenue.(\s\w{3}\s\d{2}){0,1}\s+)(-|-\d+|(\d+)|\d+[^)\w]).").Value)

1 Like

Hi @Anonymous2

What actually you want as the output can you specify ??

Means the date you want or only the 5 digit last no …

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi

In my earlier post for EG1 & EG2 I have stated the output as my Ans. So I only want the number after the date. The number could be any length.

Thank you

Hi @Anonymous2

Below is the regex for the same :-

image

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi

Thanks for the reply. But there could be instances when there are more than 1 number, or it could be a combination of dashes & numbers.

So a regex expression that excludes the date if it appears would be preferred
Is this the correct way

(\s\w{3}\s\d{2}){0,1}

to represent 'Mar 19"? I used {0,1} be’cos only sometimes is the date present. Thank you

EG3
Revenue as of Mar 19 12200 -
Ans: 12200 -

EG2
Revenue as of Mar 19 - 12200
Ans: - 12200

Hi @Anonymous2

As per the requirement i have updated the regex

image

Are you looking for the same ??

If above is the expected output

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi

I forgot to mention that the number may contain , or . And there may be 2 numbers. It could be any combination of “-” & numbers.

EG 4
Revenue as of Mar 19 12,200 5,000
Ans: 12,200 5,000

EG 4
Revenue as of Mar 19 12,200 5,000 6,000
Ans: 12,200 5,000 6,000

@Anonymous2 Could you please provide all possible inputs? :sweat_smile: In that way we can provide the correct pattern.

Hi @Anonymous2

Actually @supermanPunch is saying right :sweat_smile:
Bcz everytime then the regex gets update in various ways

Now Below is the updated regex for all the inputs you provided

image

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi

Thank you for your help. But the possibilities are many. The regex expression must be robust to consider all possible cases of a combination of number & dashes.

  1. There could be up to 8 number or dashes.
  2. The last item in the line could be a number or dash.
  3. The numbers could contain “.” , “,”, brackets, or negative number.

Here are some further examples. Thank you
EG 4
Revenue as of Mar 19 12,200 - 5,000
Ans: 12,200 - 5,000

EG 4
Revenue as of Mar 19 12,200 5,000 -
Ans: 12,200 5,000 -

EG 4
Revenue as of Mar 19 12,200 (5,000)
Ans: 12,200 (5,000)

EG 4
Revenue as of Mar 19 12,200 -5,000
Ans: 12,200 -5,000

Hi @Anonymous2

May be you are finding the below robust Regex as i have updated again :-

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

1 Like

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