• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1273
  • Last Modified:

simple split using regex in javascript

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
0
ecupd
Asked:
ecupd
  • 2
1 Solution
 
Michel PlungjanIT ExpertCommented:
regex = eval("/"+streetAddress+"/gi");
0
 
Michel PlungjanIT ExpertCommented:
or nicer

regex = new RegExp(streetAddress,"gi");      
0
 
ecupdAuthor Commented:
fantastic! thanks mate, i was going spare over that.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now