mike
mike

Reputation: 8141

javascript regex split

Is it possible to split a string twice with regex? For example, say I have the string:

[email protected]|fname|lname

how can I split to the result is:

[email protected],fname,lname

thanks...

Upvotes: 0

Views: 429

Answers (3)

zod
zod

Reputation: 12417

You want to search and replace the '|' to ' , '.

Why dont you use replace()

http://www.w3schools.com/jsref/jsref_replace.asp

Upvotes: 0

thejh
thejh

Reputation: 45568

How about this?

var result=myString.split("=", 2)[1].split("|");

Upvotes: 1

SLaks
SLaks

Reputation: 887285

You can manually remove the prefix:

str.substr(str.indexOf('=') + 1)
   .split('|')

Upvotes: 5

Related Questions