bmichotte / RegexUtil

Library to simplify regex in swift
MIT License
0 stars 1 forks source link

Invalid match result when input contains Unicode characters #2

Open fmoraes74 opened 3 years ago

fmoraes74 commented 3 years ago

The following lines https://github.com/bmichotte/RegexUtil/blob/master/Sources/Regex.swift#L63 through https://github.com/bmichotte/RegexUtil/blob/master/Sources/Regex.swift#L66 can be converted to

let range = Range(resultRange, in: someString)

That will produce the correct output when processing a string with Unicode characters.

For example:

D 22:41:54.4248610 PowerTaskList.DebugPrintPower() - BLOCK_START BlockType=POWER Entity=[entityName=เหรียญ id=15 zone=PLAY zonePos=0 cardId=SCH_247 player=1] EffectCardId=System.Collections.Generic.List`1[System.String] EffectIndex=0 Target=0 SubOption=-1 

when processed with .*BLOCK_START.*BlockType=(POWER|TRIGGER).*id=(\\d*).*(cardId=(\\w*)).*player=(\\d*).*Target=(.+).*SubOption=(.+) will show the id as 5 instead of 15 (and so on for the matches after it)

fmoraes74 commented 3 years ago

FYI, I forked and made the change on my fork:

https://github.com/fmoraes74/RegexUtil/commit/e29c499bf18741342dfc49f1ed16a20b89191d5d

bmichotte commented 3 years ago

Hi, feel free to make a PR to fix it :)

fmoraes74 commented 3 years ago

Will do after I confirm it works in HSTracker with the fixed package