Question: I never wrote any complex regular expression before, and what I need seems to be (at least) a bit complicated.

I need a Regex to find matches for the following:

```
"On Fri, Jan 16, 2015 at 4:39 PM"

```

Where `On` will always be there;

then 3 characters for week day;

`,` is always there;

space is always there;

then 3 characters for month name;

space is always there;

day of month (one or two numbers);

`,` is always there;

space is always there;

4 numbers for year;

space `at` space always there;

time (have to match `4:39` as well as `10:39`);

space and 2 caps letters for `AM` or `PM`.

Answer: 
You could try the below regex and it won't check for the month name or day name or date.

```
^On\s[A-Z][a-z]{2},\s[A-Z][a-z]{2}\s\d{1,2},\s\d{4}\sat\s(?:10|4):39\s[AP]M$

```

[DEMO](http://www.rubular.com/r/yQcktbdo8t)
The way you are describing the problem makes me thing that the format will always be preserved.

I would then in your case use the `Time.parse` function, passing the format string

```
format = "On %a, %b"On Fri, Jan 16, 2015 at 4:39 PM", format)

```

which is more readable than a regexp (in my opinion) and has the added value that it returns a `Time` object, which is easier to use than a regexp match, in case you need to perform other time-based calculations.

Another good thing is that if the string contains an invalid date (like "On Mon, Jan 59, 2015 at 37:99 GX" ) the `parse` function will raise an exception, so that validation is done for free for you.