Regex returned Empty matches!

I am facing a problem when using Match activity in Uipath. I am trying to match this string:

G 3940UNL 10k 29.5 2615 N 3957 59.5 6528 0G N G N G 920SNL 5k 29 1277 N 925 43 2174 0G 1795Clear 5k 46 2373 N 1805 74 4146 0G N G 1360Dyed 10k 33 3051 N 1366 43.5 4415 0

Regex i used is (G N)(G\s[0-9]{2,6})*, i want to match any “G N” or “G ‘number’”. There’s total of 7, and it needs to be 7.

It looks like it is working in Regex Builder, but when i test it, it returned with a lot of empty matches. I think it is because the spaces are being matched as well. I guess what i am asking is how to remove the empty matches that was included in the match result, or how i do modify my Regex to be more precise. (removing space in the string is not an option, unless i can match exactly 7 instances of “GN” and “G’Number’” in total, which i dont know how to do)

Thanks All!

@siming
In such cases https://regex101.com/ for RegEx Pattern Development can help
Give a try on this pattern: ((G N )*)(G\s[0-9]{2,6})

I am using https://regexr.com/ for development, and unfortunately ((G N )*)(G\s[0-9]{2,6}) didn’t have any match to the above string.

like this? Here we do have matches

did I get you wrong?

Sorry, i wasn’t completely clear, this Regex only returned 4 matches, for example, G N G N G 920 was considered one match, but i need it to be 3 separate matches, G N , G N , and G 920

OK perfect. But unfortunately now i do Not understand you. Can you please some help and can Highlight in your Sample Text manually the expected result. Thanks

@siming
can you check ((G N )|(G\s[0-9]{2,6})) -? (-Questionmark not part of the pattern)

1 Like

Thank you, that worked exactly as expected! I think “|” was exactly what was missing for my case. So thank you so much!

@siming
Perfect, so if it is working, you can close the topic with flagging the solving post as solution. Other can benefit from this feedback. thanks

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