need help on a regular expression of text OR text OR etc...

M

mike

Hi,

I have text in a field coming from a database. The text has various
forms such as:

text1
text1 or text2
text1 or text2 or text3
text1; or text2
text1; or text2; or text3
etc...

how can I parse this with a reg ex? I tried this:

(.+);? or

but it only captures 1 submatch (text1) and only if theres an "or"
after it

I'd like to get 1 submatch for each piece of text separated by the
"or", just the text itself if there is no or.

Anyone know how to do it?
 
J

julie lawrence

mike said:
Hi,

I have text in a field coming from a database. The text has various
forms such as:

text1
text1 or text2
text1 or text2 or text3
text1; or text2
text1; or text2; or text3
etc...

how can I parse this with a reg ex? I tried this:

(.+);? or

but it only captures 1 submatch (text1) and only if theres an "or"
after it

I'd like to get 1 submatch for each piece of text separated by the
"or", just the text itself if there is no or.

Anyone know how to do it?

I would get rid of the ';' first, if they're not important
sText = sText.replace(/;/g, ''); // get rid of the ';'s

then split the text into an array on the "or" word, i.e.
var myArray = sText.split(' or ');

cheers,
Julie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top