split string at ">" only if the next charakter is a "<" in javascript

You can achieve this using the split() method with a regular expression as its argument. The regular expression should match the ">" character followed by a "<" character. Here's an example code snippet:

index.tsx
const myString = "Hello>world<how>are<you>doing<today";
const myArray = myString.split(/>+</);

console.log(myArray);
// Output: ["Hello", "world", "how", "are", "you", "doing", "today"]
187 chars
6 lines

In the regular expression />+</, > matches the greater than sign, < matches the less than sign, and + matches one or more of the preceding character (in this case, the closing > and opening < brackets). This regular expression matches the desired pattern and splits the string accordingly.

related categories

gistlibby LogSnag