开发者

Regex for AMon:1

I'm a bit rubbish with Regex and was wondering if some kind person would be happy to assist!

The format is:

optionally 1, 2 , A or B

Day Name, possibly short or full, eg Mon, Tuesday, Thursday, Fr

Colon : or Space

Integer

The following are valid: EDIT: included "Mon:20"

Mon:3, Tuesday:6, AWe:9, 2Fr:2, 2Wed 3, Friday 6, Mon:20

The following is not valid:

3Mon:1, Mon3, 3:Wed

I woul开发者_开发问答d presume for the day name, we can just check for A-Z,a-z starting with Mo,Tu,We,Th,Fr,Sa,Su ending with a colon or use piping and specify every possibility ie Mo|Mon|Monday|Tu|Tue|Tues|Tuesday, etc.

Thanks ever so much


[12AB]?(Mo|Tu|We|Th|Fr|Sa|Su)\w*[: ]\d+


This checks the days of the week more strictly than the other answer:

/[12AB]?(
    Mon?|
    Tu(es?)?|
    We(d(n(es?)?)?)?|
    Th(u(rs?)?)?|
    Fri?|
    Sa(t(ur?)?)?|
    Sun?
)(d(ay?)?)?
[: ]\d+/


Realised I needed to return true for

TuA:2

This is the solution I've ended up with for the moment:

([12AB]?)[: ]*(Mo|Tu|We|Th|Fr|Sa|Su)(\w*)[: ]*(\d)+

This allows me to pick out the leading A,B,1,2, the day Mo,Tu,We... and whats after the day, "A" in the example above or otherwise "esday" for "Tuesday", and it returns the last digit too.

Thanks everyone for putting me on the right track.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜