Javascipt Regular Expression

Posted by Ghoul Fool on Stack Overflow See other posts from Stack Overflow or by Ghoul Fool
Published on 2012-09-07T09:12:06Z Indexed on 2012/09/07 9:38 UTC
Read the original article Hit count: 181

Filed under:
|

Having problems with regular expressions in JavaScript. I've got a number of strings that need delimiting by commas. Unfortunately the sub strings don't have quotes around them which would make life easier.

var str1 = "Three Blind Mice 13 Agents of Cheese Super 18"
var str2 = "An Old Woman Who Lived in a Shoe 7 Pixies None 12"
var str3 = "The Cow Jumped Over The Moon 21 Crazy Cow Tales Wonderful 9"

They are in the form of PHRASE1 (Mixed type with spaces") INTEGER1 (1 or two digit) PHRASE2 (Mixed type with spaces") WORD1 (single word mixed type, no spaces) INTEGER2 (1 or two digit)

so I should get:

result1 = "Three Blind Mice, 13, Agents of Cheese, Super, 18"
result2 = "An Old Woman Who Lived in a Shoe, 7, Pixies, None, 12"
result3 = "A Cow Jumped Over The Moon, 21, Crazy Cow Tales, Wonderful, 9"

I've looked at txt2re.com, but can't quite get what I need and ended up delimiting by hand. But I'm sure it can be done, albeit someone with a bigger brain. There are lots of examples of regEx but I couldn't find any to deal with phrases; so I was wondering if anyone could help me out. Thank you.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex