简体   繁体   中英

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

hi i need to match the following string in c#

for example

-34

-67

-23

-46

-00

i would loop over the string and check each char but thats messy and i have no idea about regex so was hoping for some help.

thanks

以下正则表达式应该工作

@"-\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);

我认为-\\ d \\ d应该可以做到

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM