We help IT Professionals succeed at work.

simple split using regex in javascript

ecupd
ecupd asked
on
1,290 Views
Last Modified: 2008-01-09
Hi,
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

Cheers,

dayton
Comment
Watch Question

Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
regex = eval("/"+streetAddress+"/gi");
IT Expert
CERTIFIED EXPERT
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
fantastic! thanks mate, i was going spare over that.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.