0

I'm using Autoblogged to pull a feed in as a blog post. I need to create a reg expression to convert the title of the item to things I can use as meta data. I've attached a screen of the backend I have access to. Any help would be greatly appreciated!

Here are examples of the title from the feed.

Type One Training Event New New Mexico, WY November 2012

Type Two Training Event Seattle, WA November 2012

I need that to become this:

<what>Type One Training Event</what> <city>New New Mexico</city>, <%state>WY</state> <month>November</month> <year>2012</year>

<what>Type Two Training Event</what> <city>Seattle</city>, <state>WA</state> <month>November</month> <year>2012</year>

Essentially says take whatever is before the word event and make that "what"

Take anything after the word event and before the comma and make that "city"

Take the two letters after the comma and make that "state"

Take the last two words and make em month and year

Autblogged backend:enter image description here

McPace
  • 41
  • 1
  • 9

2 Answers2

0

Perhaps match:

^(.* Event) (.*), ([A-Z]{2}) +(?i(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)) +((?:19|20)\d{2})\b

EDIT: re your comment, it looks like you have to surround your regex in delimiters. Try:

/insert_above_regex_here/

If you want case-insensitive, then do:

/insert_above_regex_here_but_remove_(?i_and_matching_)/i

However if you do case-insensitive, your state ([A-Z]{2}) will also match two lower-case letters. If this is OK then go for it. You culd also try changing that part of the regex to (?-i([A-Z]{2})) which says "be case-sensitive for this part", but it depends on whether that engine supports it (don't worry, you'll get an error if it doesn't).

Then replace with:

<what>$1</what> <city>$2</city>, <state>$3</state> <month>$4</month> <year>$5</year>

I'm not sure what flavour of regex that interface has so you might not be able to do the (?i bit in the Month regex (it just makes that bit case insensitive) -- you'll just have to be careful then to write your months with one capital letter and the rest lowercase, or you can modify the regex to allow upper-case too.

mathematical.coffee
  • 55,977
  • 11
  • 154
  • 194
  • Thanks for the quick reply! I've tested your code and the plugin threw an error. I'll investigate the error with the plugin authors. preg_replace() [function.preg-replace]: No ending delimiter '^' found in /wp-content/plugins/autoblogged_v29rc1/autoblogged.php at line 2657 – McPace Jan 26 '12 at 15:20
  • Oh, it might want you to surround your regex in delimiters: basically, `/insert_regex_here/`. I'll update my answer. – mathematical.coffee Jan 27 '12 at 00:13
  • AutoBlogged will take the regex with or without the delimiters. If you leave them off it will use /regex_pattern/si. – AutoBlogged Jan 27 '12 at 05:19
  • Thanks for the attention mathematical.coffee. Looks like I'm waiting for the 2.9 release. – McPace Jan 27 '12 at 15:46
0

We actually have an email in queue to respond to you directly once we get our v2.9 update out. The update fixes a bug in the regex feature but I thought I would go ahead and comment here so this question isn't just left open.

The ability to extract info from a feed is one of the coolest and most powerful features of AutoBlogged and this is a perfect example of what you can do with those features.

First of all, here are the regex patterns you would use:

What: (.*)\sTraining\sEvent

City: Training\sEvent\s([^,]*)

State: .*,\s([A-Z]{2})

To use these, you create new custom fields in the feed settings. Note that the custom fields also use the same syntax as the post templates so you can use the powerful regex function to extract info from the feed. This is how the fields should look:

Custom Fields

Once you create these custom fields you can use them in your post templates and they will be added as custom fields to your post in WordPress.

Once you have these custom fields set up, you can use them in your post template as %what%, %city% or %state_code%. As I mentioned before this will also create custom fields on your blog post in WordPress as well. If you don't want that, you can just use %regex("%title%", "(.*)\sTraining\sEvent", "1")% instead of %what% directly in your post template.

Quick explanation of the syntax: If you use %regex("%title%", "(.*)\sTraining\sEvent", "1")% it means this:

  • Get this info from the %title% field
  • Use the regex pattern (.*)\sTraining\sEvent
  • Use match reference 1, the (.*) part.
AutoBlogged
  • 116
  • 1
  • Thanks AutoBlogged! Yes I'm aware of my 3 month old ticket in your support system. I am still waiting for additional details like these to know that I would be able to finish my project. I'm using 2.9 RC1 and this still doesn't work. This is a great explanation that I wish you would've used in my support ticket. If anyone would like to also track this process it's at [http://community.autoblogged.com/requests/5891](http://community.autoblogged.com/requests/5891) – McPace Jan 27 '12 at 15:45
  • That's actually a private ticket, no one else can access it. Wow 3 months?! – AutoBlogged Jan 28 '12 at 09:11
  • Yeah nevermind the ticket everyone. Anyone wondering between WPMU.org's Autoblog and Autoblogger, the answer by far is Autoblogger! Thanks I'm up and running and now I'm thinking of how else this plugin can make my life easier. – McPace Jan 31 '12 at 21:52
  • Here's a follow up to that. The date of my feed is (D, d M Y G:i:s e) how would I use convert that to (F j, Y)? – McPace Apr 19 '12 at 00:00