ID:2112039
 
When dealing with mouse-tracking, it's useful to be able to split a screen_loc into its parts; map ID, tile X, step X, and tile Y.

If you want to extract information from screen-locs in this format:
// map_id, step_x, and step_y are optional!
"[map_id]:[tile_x]:[step_x],[tile_y]:[step_y]"

// e.g.
"map:1:2,3:4"
"5:6,7:8"
"9,10"

Then you can use this regex, like so:
var global/regex/ScreenLocParser = regex(
"^(?:(?!\[0-9]+:)(\\w+):)?(\\d+)(?::(\\d+))?,(\\d+)(?::(\\d+))?$")

// is screen_loc a valid screen_loc?
if(ScreenLocParser.Find(screen_loc))
// just by calling regex.Find(), the regex.group variable now contains the relevant pieces:
// (if any of the optional parts are missing, they'll be null here)
var map_id = ScreenLocParser.group[1]
var tile_x = text2num(ScreenLocParser.group[2])
var step_x = text2num(ScreenLocParser.group[3])
var tile_y = text2num(ScreenLocParser.group[4])
var step_y = text2num(ScreenLocParser.group[5])

This regex does not parse screen_locs that contain spaces, arithmetic expressions, or anchors, such as:
"WEST + 1, NORTH - 1"

I'll leave that to you, or maybe I'll do it myself if I'm lazy enough.

This regex also doesn't expect map IDs to be strings of only digits.