I want to extract number from string

Hi,

Below is the string. In this string i want to extract 201-396 value this value get change in other string the only thing which stable is the last part of string which is after 396 and Count is stable rest thing change. Now how to get the value

Count: PGI 04 201-396 mode: Unknown alarm: Unknown interface: integrated

@Puneet_Singh1
Give a try on regex Pattern
\d+-\d+

1 Like

Thanks @ppr

One more question how to extract PGI 04 value it might different string to string like DGI 05 or else.

@Puneet_Singh1 - You can try the below pattern…

For testing purpose, I have put both texts …

@prasath17

System.Text.RegularExpressions.Regex.Match(Cable,“(?<=Count:\s)\w{3}\s?\d{2}”).Value

This is returning “” null value. Please let me know where i am incorrect

@Puneet_Singh1 - it’s working for me…

I am storing this value Count: PGI 04 201-396 mode: Unknown alarm: Unknown interface: integrated in Cable variable and then i am using below regex
System.Text.RegularExpressions.Regex.Match(Cable,“(?<=Count:\s)\w{3}\s?\d{2}”).Value its same as you mention but its returing null.
anyways thanks for the support let me check

@Puneet_Singh1 - Please check if there is any additional space between the strings…

That doesn’t impact…

Dont know why i am getting null value

Your input to regex and the output variable is same? If so could you please use different one and try…

Already did that in above. My input is in strString and output storing in cable.

@Puneet_Singh1 - could you please do a write Line and print the strstring and share it with me ?

" Count: PGI 04 201-396 mode: Unknown alarm: Unknown interface: integrated "

@Puneet_Singh1 - I think there is two spaces after the colon…Please try this pattern…

Thanks Sir

1 Like

Count: PGI 04 201-396 mode: Unknown alarm: Unknown interface: integrated

@prasath17 sir please do one more help. How to extract 201 and 396 value i need both value in two different variable i mean 201 in one variable and 396 in another and these value will change workorder wise.

Thanks in advance. Please help i stuck here.

hi @Puneet_Singh1 - Please try this pattern…

StrMatches = System.text.regularexpressions.regex.matches(StrInput,“(\d+)-(\d+)”)

Here StrMatches is of variable type ‘MatchCollection’

Variable 1 = StrMatches(0).groups(1).tostring
Variable 2 = StrMatches(0).groups(2).tostring

1 Like

Getting this error