Regex.Split with Number as Delimiters

Hi

*** Q (without M2) = 0.81 CONDITIONALLY ACCEPTED.

I want to extract all the words after the number 0.81 which varies for every .txt file.

I tried the below but it doesn’t work

(System.Text.RegularExpressions.Regex.Match(Text1,"(?<=(without M2)).+").Value).ToString.Split("\d+".ToCharArray).last

1 Like

@Anonymous2

Try below regular expression to get required value from above string.

                 (?<=\d.\d{2}\s).+

Hi

Thanks for the reply. We need (without M2) to identify the line, so we can’t use

(?<=\d.\d{2}\s).+

I tried the below but I get the error that there are too many s. So how should I solve the problem? Thanks

(System.Text.RegularExpressions.Regex.Match(Text1,"(?<=(without M2)\s+=\s+\d+.\d+)).+").Value)

Can you send some sample lines, how it looks?

Checking the String (without M2) and getting the String after the digit in Group 1.

Thanks
@Anonymous2

Manish540Robot Master

8m

Can you send some sample lines, how it looks?

====================
Hi

Thank for the reply. The sample line is

*** Q (without M2) = 0.81 CONDITIONALLY ACCEPTED.

The number 0.81 varies for every .txt file. There are a lot of other lines in my .txt file, so I need (without M2) to identify the above line.

Thank you

Check with this regex,
(?<=without M2).+(?<=\d.)(\w.*)

1 Like

Hi

It doesn’t work. I get back

) = 0.81 CONDITIONALLY ACCEPTED.

@Anonymous2 Try this and let me know

Regex

Result

image

Use Group(1) , you will get it.

1 Like

Do as below screenshot,


Use below code you will get the match collection,
System.Text.RegularExpressions.Regex.Matches( Str,"(?<=without M2).+(?<=\d.)(\w.*)")
Then, pass this match collection to “for each” and use “item.Groups(1)”.
And in properties panel of for each make "TypeArgument " of match.

Hi Indra

Thanks for the comprehensive explanation. But as said I need (without M2) to identify the line, which your solution lacks.

Hi Manish540,

I used the below, and managed to extract the “1 CONDITIONALLY ACCEPTED”. Any idea to get rid of the digit? Thanks

(System.Text.RegularExpressions.Regex.Match(Text1,"(?<=(without M2).+\d+.\d+).*").Value)

Hi All

I managed to solve it with

(System.Text.RegularExpressions.Regex.Match(Text1,"(?<=(without M2).+\d+.\d+\s+).*").Value)

Thanks everyone for your kind help!

1 Like