simple split using regex in javascript

Posted on 2007-10-10
Last Modified: 2008-01-09
I need to split a string with another known string while ignoring case. The string will only appear once.
So in "text1 text2 text3" i want to be able to split with "text2","TEXT2","TeXt2" etc

my code i have tried is :

regex = "/"+streetAddress+"/gi";      
splitUserEnteredAddress = userEnteredAddress.split(regex);

where an example of streetAddress could be "10 Smith St"
and an example of userEnteredAddress could be "building 300 room 10 10 SMITH st, Smithtown, WA 6000, Australia"

and i am hoping to end up with  array vars such :
splitUserEnteredAddress[0] = "building 300 room 10 "
splitUserEnteredAddress[1] = ", Smithtown, WA 6000, Australia"

any ideas?
thanks in advance


Question by:ecupd
    LVL 75

    Expert Comment

    by:Michel Plungjan
    regex = eval("/"+streetAddress+"/gi");
    LVL 75

    Accepted Solution

    or nicer

    regex = new RegExp(streetAddress,"gi");      
    LVL 2

    Author Comment

    fantastic! thanks mate, i was going spare over that.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now