Amarnath R Shenoy Amarnath R Shenoy - 3 months ago 12
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) {


Use this:

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

Working Fiddle: