Here, I have example javascipt string:
example_string = "Answer 1| Answer 2| Answer 3|";
I am trying to get array like this using regular expression:
Array ["Answer 1", " Answer 2", " Answer 3"]
I have tried:
result = example_string.split('/[|]+/g');
and also with the following patterns
'/[|]+/g'
'/[|]+\b/g'
'/[|]+[^$]/g'
And I am still getting an array with empty element at the end of it:
Array ["Answer 1", " Answer 2", " Answer 3", ""]
That cause me lot of trouble. Does anyone know where I am making mistake in my pattern or how to fix it?
I always liked matching everything I always hated split but:
Regex for splitting:
(\|(?!$))DEMOMatching instead of splitting:
Regex:
(?:([\w\s]+)\|?)You can even use
[^\|]+To match whatever you have to match BUT|DEMO