Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split a string

Status
Not open for further replies.
Jul 29, 2005
136
PT
Hello,

I need to split a string in the folowing way:

Example string: "This is a test [@something] for spliting a string [@something_else].

I would like to get an array like this:

arr(0)= "This is a test "
arr(1)= " for spliting a string "
arr(2)= "."

In other words, I would like to split a string finding a substring that begins with "[@" and that ends with "]" (the first "]" after an "[@".

Any ideas?

thank you
 
[tt]var s="This is a test [@something] for spliting a string [@something_else].";
var arr=s.split(/\[@[^\]]*\]/);[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top