Negative number in world file regex?

Hello,

Not sure if it’s a bug or i’m doing something wrong.

I have world file defined with regexp looking like this:

    {
        "patterns": [
            {
                "regexp": "map_-*(\\d+)_-*(\\d+)\\.tmx",
                "multiplierX": 16,
                "multiplierY": -16,
                "offsetX": 0,
                "offsetY": 0
            }
        ],
        "type": "world"
    }

Everything is working fine and chunks are rendered correctly when i’m using positive values in file names.
When negative value is used in file name. Tiled simply omits “-” value and file is rendered like it was positive value.

Correctly loaded files:

map_0_0.tmx
map_128_192.tmx

Incorrectly loaded files:

map_-64_128.tmx

You need to make sure that the minus is part of the capture. I think this would work:

"regexp": "map_(-?\\d+)_(-?\\d+)\\.tmx"

Thanks, it works!

I was validating my regex using https://regex101.com/
And i wasn’t careful enough to spot that “-” has not been captured as part of the number.

Thanks a lot for help.

1 Like