Char by char.
For example this website I did
https://lainz.github.io/webapps/pseudocodigo/That converts from Spanish Pseudo code language to JavaScript
view-source:https://lainz.github.io/webapps/pseudocodigo/app.js
And yes, I can differentiate between keywords and variables.
I can find them no matter the ammount of spaces that are between words. Because I skip these spaces. As you can see in the sources there is also a list of keyworkds and operators I use to determine everything.
Is not perfect, but there you have code you can use.
I will add a demo, but not now since I'm working
In simple terms: ignore spaces, ignore everything you don't need.
Or if you want to do it really well, analyze everything, spaces, symbols, all, so you know exactly what is typed and what you need to extract from there.