Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > need help on a regular expression of text OR text OR etc...

Reply
Thread Tools

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

 
 
mike
Guest
Posts: n/a
 
      10-03-2006
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?

 
Reply With Quote
 
 
 
 
julie lawrence
Guest
Posts: n/a
 
      10-03-2006
mike wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
Need a Regular expression to remove a char for Unicode text =?utf-8?B?4LC24LGN4LCw4LGA4LCo4LC/4LC14LC+4LC4?= Python 4 10-13-2006 12:11 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments