开发者

Regular Expression for a project Number help

I am in need of some regular expression help. (regex is not my strong point!) I have to iterate through a spreadsheet and match the strings that look like this:

AZP2006-开发者_如何学编程056.03

ABC####-###.##

so first three can be any letter, four digit year and a 3 digit number with a two decimal place value.

Can someone please help me with te regular expression to match this case?

Thanks!


[A-Z]{3}\d{4}-\d{3}\.\d{2}

I'm not sure if you have to escape the hyphen in -\d{3}


\w{3}\d{4}-\d{3}\.\d{2}

This is a pretty simple regex, even if you're new to it a few minutes of reading documentation and trying things out should be enough to come up with something that works. I'd suggest using a tool like this to interactively see what your pattern is matching:

http://gskinner.com/RegExr/


This should do the trick.

\w{3}\d{4}-\d{3}\.\d{2}


I think this should work: [a-zA-Z]{3}[0-9]{4}-[0-9]{3}.[0-9]{2}


I know it's pretty late to answer this now, but I do note that you said the 4 digit number following the letters was to be the year.

To avoid getting something like ABC9786-654.43, it would also be good to validate the year so I would use:

(?#better version - validates year)^[A-Z]{3}(?<year>((19)[0-9]{2})|((20)[01][15]))-\d{3}\.\d{2}$
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜