开发者

Regex to match the pattern [-][number][number]

开发者 https://www.devze.com 2023-02-05 19:15 出处:网络
hi i need to match the following string in c# for example -34 -67 -23 -46 -00 i would loop over开发者_如何学Go the string and check each char but thats messy and i have no idea about regex so

hi i need to match the following string in c#

for example

-34

-67

-23

-46

-00

i would loop over开发者_如何学Go the string and check each char but thats messy and i have no idea about regex so was hoping for some help.

thanks


The following regex should work

@"-\d\d"


-(\d\d) is the pattern

Regex rx = new Regex(@"-(\d\d)");
var matches = rx.Matches(str);
foreach (var match in matches)
    Console.WriteLine(match.Groups[1].Value);


I think -\d\d should be able to do it

0

精彩评论

暂无评论...
验证码 换一张
取 消