Help with decoding website data using string patterns

Hey all :wave: I’m trying to decode a string I got from a website using string patterns, and it seems I did everything right but it keeps returning nil

local _string = [[<span class="js-symbol-rtc-time">(08:59 UTC-5)]]
local _variable = _string:match([[<span class="js%-symbol%-rtc%-time">%([%d+]%p[%d+]%s[%u+]%-%)]])
print(_variable)

Here’s the string patterns:


Here’s the magic characters

it’s obvious that in the string there are magic characters, and I preceed them with a % symbol, I don’t know what I’m doing wrong.

1 Like

Ok, so I fiddled around with this and got it to work:

local _string = [[<span class="js-symbol-rtc-time">(08:59 UTC-5)]]
local _variable = _string:match([[<span class="js%-symbol%-rtc%-time">%(%d+%p%d+%s%u+%-%d%)]])
print(_variable)

Turns out, your mistake was adding character classes in this string:

'([%d+]%p[%d+]%s[%u+]%-%)'

It can simply be:

'(%d+%p%d+%s%u+%-%)'

Plus, you forgot a %d at the end for UTC-5, so it should be this:

'(%d+%p%d+%s%u+%-%d%)'
1 Like