1

I have a a feed who's date is formatted like 'D, d M Y G:i:s e'

Autoblogged has a reg expression engine.

What is the regular expression to convert 'D, d M Y G:i:s e' to 'F j, Y'?

Again I want to convert 'Fri, 20 Apr 2012 12:00:00 EST' to 'April 20, 2012' where the date is stored in variable %:pubDate%. I'm using Autoblogged for Wordpress.

McPace
  • 41
  • 1
  • 9
  • A regular expression can't easily get 'April' out of 'Apr'. You'll wind up with 13 regular expressions, one to move things around, and one for each month to expand the abbreviation. Does Autoblogged not have any other tools for this? – Mark Reed Apr 19 '12 at 00:22
  • They have a search and replace feature, which can also use regex. – McPace Apr 19 '12 at 00:33

1 Answers1

0

Regex cannot convert strings, but it can find and parse them.
This regex will do what you want.

Put this in the "Search for" field (assuming that the dates are formatted exactly like Fri, 20 Apr 2012 12:00:00 EST):

[a-zA-Z]{3}, ([0-9]{1,2}) ([a-zA-Z]{3}) ([0-9]{4}) [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2} [a-zA-Z]{3}

And this in the "Replace with" field:

$2 $1, $3

See this for a demonstration: http://regex101.com/r/tP6hU7

You can then replace

  • Jan(?:uary)? with January,
  • Feb(?:ruary)? with February,
  • etc.

Input: Fri, 20 Apr 2012 12:00:00 EST
Output: April 20, 2012

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75