OK so. Regex in Javascript isn't exactly gloriously implemented.
Hypothetical string:
10275:cat40089:10277:20.00-35.00|35.00-50.00:10277:20.00-35.00|35.00-50.00:12277:34|36:12275:C|D
The regex:
/(^|:)[0-9]{5}:[\w\.|-]+/g
The loop, minus a few lines of irrelevant code
do
{
result = rgx.exec(hashstring["trail"])[0];
if(result.substring(0,1) == ":")
{
result = result.substring(1);
}
if(result.substring((result.length - 1), result.length) == ":")
{
result = result.substring(0, (result.length - 1));
}
result = result.replace(",", "");
var thesplit = result.split(":");
hs.push({key:thesplit[0], value:thesplit[1]});
}
while (result != null);
Everything works, the problem is I am getting a null exception at the end of the loop. I have a feeling the "while not null" condition is inherently flawed, but I can't think of any sort of limiting condition. The real problem is that the Regex object doesn't tell you how many matches it can find. It just gives you the first one and you have to keep calling it until it coughs up an error.
It's really strange and I've seen it done almost identically on other sites without it fucking up. I think, perhaps, I am missing something critical.
TIA
*edit* note that doing a try catch on the assignment of result will cause a very delightful endless loop.
*edit2*
I ended up having to write the do block like this:
var theres = null;
try
{
theres = rgx.exec(hashstring["trail"])[0];
}
catch(e){}
if(theres != null)
result = theres;
else
result = null;
if(result != null)
{
if(result.substring(0,1) == ":")
{
result = result.substring(1);
}
if(result.substring((result.length - 1), result.length) == ":")
{
result = result.substring(0, (result.length - 1));
}
result = result.replace(",", "");
var thesplit = result.split(":");
hs.push({key:thesplit[0], value:thesplit[1]});
}
For some reason assigning straight to result with try/catch caused it to flip the fuck out, so I used an intermediary variable. This just seems
wrong. I'm looking for a better way to write this.
this is a discord of mostly PA people interested in fighting games:
https://discord.gg/DZWa97d5rz
we also talk about other random shit and clown upon each other
Posts