Skip to content
Advertisement

String tokenizer method

Consider strings with this format:

JavaScript

where id, string1, string2 and string3 can be string of variable length, and extension is an image extension type.

For example, two possible strings could be:

JavaScript

I need tokenizer method in JavaScript for an express/nodejs API that takes these strings in input and outputs an object with this format:

JavaScript

For the example strings this tokenizer should then output:

JavaScript

I think this can be done with regex. I tried to use the following regex match(/[^-]+/g), but this tokenize every substring, I need a way to skip the first 2 char “-” but couldn’t find it out.

Do you have any ideas? Or could you provide me a better solution instead of using regex? Thanks very much!

Advertisement

Answer

You can achieve this using spit as:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement