Need help understanding how to create modes

I’ve searched everywhere for help on this but it seems like I’m the only one whose having an issue. To sum up my situation, I’m new to codemirror, and I need to create a mode so I can use some functions I plan to create. I’ve gone over the manual and simplemode example many times, but I don’t understand what is going on, probably because I’ve never dealt with something like this. Going off the simplemode example found at I’m confused what states are(start, comment, and meta) and what their purpose is. Also I am extremely confused about what regex and tokens are. It says the regex matches the token and the token has a type but the regex just looks like somebody pressed about 20 random keys. Lastly as I said before I’m trying to create a mode for a few functions, but just so i can get an understanding of how things work I’m trying to create a simple math mode where you can add, subtract, multiply, and divide numbers in the editor. I’m not asking to have you create the mode for me, just to help me understand what i need to do so i can do it on my own. Sorry for the very long newbie question but I’ve been trying to figure this out for a couple days now and I haven’t gotten anywhere. Thanks in advance!

I see. It sounds like you’ll have to do a bunch of research and learning first. Regular expressions (regexps) are a way to describe patterns in strings, for example to recognize syntactic elements in a programming language. A good start, when it comes to figuring them out, is this chapter in my book. Maybe other parts of that book are also helpful to you.

The ‘state’ thing, in this case, comes from the computer science concept of a finite state machine. You might also be able to get some more insight from my blog post about CodeMirror’s mode system (but note that the simple mode addon, which you’ll probably want to use, is a more abstract, convenient layer on top of that system).

Thank you very much for the guidance, I knew this was out of my comfort zone but I’ve been tasked to do it so thank you for giving me some knowledge on the subject. I will keep you informed if i need help after I’ve done my research.