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

Discussion in 'ASP General' started by mike, Oct 3, 2006.

  1. mike

    mike Guest

    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?
     
    mike, Oct 3, 2006
    #1
    1. Advertising

  2. 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
     
    julie lawrence, Oct 4, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,332
  2. Andrew Banks
    Replies:
    2
    Views:
    20,921
    Andrew Banks
    Jan 5, 2004
  3. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    861
    Alan Moore
    Dec 2, 2005
  4. =?utf-8?B?4LC24LGN4LCw4LGA4LCo4LC/4LC14LC+4LC4?=

    Need a Regular expression to remove a char for Unicode text

    =?utf-8?B?4LC24LGN4LCw4LGA4LCo4LC/4LC14LC+4LC4?=, Oct 13, 2006, in forum: Python
    Replies:
    4
    Views:
    1,515
    Leo Kislov
    Oct 13, 2006
  5. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    431
    Fredrik Lundh
    Aug 13, 2008
Loading...

Share This Page