Regex to get number

Hi All,
Need some help related to regex if possible.
I have a table in which one of the column consist of Remarks.
From this remarks column i need to collect a number which can be upto 9999(i.e between 1 to 9999)
This number should be collected only if that column contains some keyword. And the number should be just before or after that keyword.
For example: consider ‘number’ is the keyword.
number is 20
20 is the number
number = 20

so if remark column contains something like above then i need to fetch 20

Is it possible to create a regex? Can you please help


Hi @Deepa_Madkar ,

Sure, you can get a number from a string variable say str as: System.Text.RegularExpressions.Regex.Match("str, “\d+”).
If some of the row doesn’t have the column then the above regex expression will return “” (empty string).

HI @Deepa_Madkar

Checkout this Expression

System.Text.RegularExpressions.Regex.match("InputString","(?<=number\s=\s)\d+|(?<=number\sis\s)\d+|\d+(?=\sis the number)").Tostring


Hi @Sudharsan_Ka thanks for the reply.
If that keyword is coming from some variable then how we can include that variable in regex? Can you please help

Thanks for the reply @Aakash_Singh_Rawat
I get your point. But this remarks can have multiple numbers so i want the number which will be prefix or suffix to that keyword

Hi @Deepa_Madkar ,

Could you also let us know if there would be a possibility of other numbers being present in the Remarks column ? if so, How is the retrieval done for those scenarios ?

Are the above examples the only pattern that will be observed in the remarks column ? A more real data scenario on this remarks column would be helpful for us to provide accurate suggestions.

Try Like this @Deepa_Madkar

System.Text.RegularExpressions.Regex.match("InputString","(?<="+StrVariable+"\s=\s)\d+|(?<="+StrVariable+"\sis\s)\d+|\d+(?=\sis the "+StrVariable+")").Tostring


Thanks for the reply @supermanPunch
yes there can be other numbers also. So i want to fetch number such that it is suffix or prefix to the keyword


Please refer to the link: Regular expression syntax cheat sheet - JavaScript | MDN

for Lookahead or Lookbehind assertion in regex pattern.

Thank you @Sudharsan_Ka
it is working. Thank you so much.

Just a query to above regex. Will it take care that the number is not more than 4 digits? The number to be fetched should be between 1 to 9999

Thank you @Aakash_Singh_Rawat

Yes it will take all the numbers @Deepa_Madkar


If your query resolve , Kindly Mark the solution and close the topic so that it will be helpful to others. @Deepa_Madkar

Happy Automation!


Oh okay @Sudharsan_Ka
But in my query i want to extract only number which will be between 1 to 9999 i.e integers upto 4 digits.
is it possible to get number like this please

OKay @Deepa_Madkar

Can you tell this

number is 20
20256 is the number
number = 2025

If this is the case you want only 20 and 2025 ?

yes correct @Sudharsan_Ka

So your actual input string will be one line right like number = 20 ? @Deepa_Madkar

Ofc you will have diff formats

There can be multiple lines . But i will be checking integers which are suffix or prefix to a keyword. This number should be between 1 digit to 4 digits. If it is more than 4 digits then i cannot consider that number


Please try this




Checkout this Expression

System.Text.RegularExpressions.Regex.Match(System.Text.RegularExpressions.Regex.Replace(InputString,"\d{5,}","(?<="+StrVariable+"\s=\s)\d{4}|(?<="+StrVariable+"\sis\s)\d{4}|\d{4}(?=\sis the "+StrVariable+")").ToString