Amarnath R Shenoy Amarnath R Shenoy - 1 year ago 100
Javascript Question

How can I split a string separated with pipe symbol using jQuery regex

I have a dynamically generated string which is basically a row with each value separated by a pipe symbol

, I need to separate it and insert them into a bunch of hidden fields .

This was almost what I needed to do, but not working for me, and I can only use (
) as special characters since my data may contain other characters.

Here is my code:

var data = "Val1@#|val2$%|val3(*|"; // dynamically generated

$.each(data.split(/\s*|\s+/), function(i, val) {

Answer Source

Use this:

var Data ="Val1@#|val2$%|val3(*|" //dynamically generated 
$.each(Data.split(/\|/), function (i, val) {

Working Fiddle:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download