Reputation: 3389
I want to split string for ">" but not when >> in JavaScript.
But once I am doing a split const words = str.split('>');
it is splitting >>
as well.
Currently, after the split I look for "> >" and then substitute them with ">>".
How to implement it properly.
Upvotes: 0
Views: 181
Reputation: 16364
You can use a regular expression leveraging:
The resulting pattern would be as follows:
/(?<!>)>(?!>)/
Using the patter to tokenize an input would lead the desired results:
"here>>I>am".split(/(?<!>)>(?!>)/) // => [ 'here>>I', 'am' ]
Upvotes: 1