In this article I will talk about how I attempted to parse the position argument of a minecraft command using regex as well as describe the regex I used to do so.
During my time working with the gametest framework for minecraft I wrote a small framework for building out custom commands. One feature sometimes used is the ability to specify a position in the world for the command to use. to do this I used a regex to locate a portion of the syntax needed to specify a position. The regular expression /^([~^]-?\d*(?:\.\d+)?|-?\d+(?:\.\d+)?)/
has a couple of parts where it looks for a prefix, and then a partial or complete number, minecraft supports 2 prefix, ~
and ^
which are used to specify a relative position, and an absolute position respectively. This regex also supports negative numbers, and numbers with decimal points as well as numbers without a prefix.