REGEX error
<sigh>
I mean, if it was not for the previous blog rant, I would not have dug into the issue and found the problem. (Well, one of the very many problem's with the site).
So there is value in setting me off into rant mode - just be sure to get out of the way and don't take anything I say while in said mode personally. I'm mostly ranting at myself.
Honestly, the real question is how in the world do so many of you avgeeks put up with this dumpster fire of a site and the beat up scrappy ally cat that is its mascot?
"And also I have to say thank you very much for being so comitted to ACARS, your website (together with Airframes) has been the biggest step forward in Aircarft tracking in the recent years."
Man, that just about brings a tear to my bald geek heart.
Ok, back to the title and subject of this blog....
I was ranting about having so many different versions / data formats for Iridium and how my site has to detect and switch between a few of them to get the data onto the site.
Well, one of you Iridium feeders pointed out that your station data was not showing up on the site search results page.
I always check when we first set you up, but then I just get busy doing other stuff and don't check back, say weekly, and so if you change anything - as was the case here - I may not notice.
So, the comment was made about said data not making it into the dumpster fire....
Guess what... Six. We now have six versions of Iridium data... Seems the station update was outside of my auto filter.
I was ranting about having so many different versions / data formats for Iridium and how my site has to detect and switch between a few of them to get the data onto the site.
Well, one of you Iridium feeders pointed out that your station data was not showing up on the site search results page.
I always check when we first set you up, but then I just get busy doing other stuff and don't check back, say weekly, and so if you change anything - as was the case here - I may not notice.
So, the comment was made about said data not making it into the dumpster fire....
Guess what... Six. We now have six versions of Iridium data... Seems the station update was outside of my auto filter.
But wait. There's more.
In digging into the format of the 6th variation (feels like the eleventy eighth variation honestly - so the actual number does not matter) - I found a fun bug with ALL the feeds....
If you recall my first Iridium blog (ok, lets call it what it was, a rant) mentioned about how mangled the irdm rego can be, here the mangle in the cross hairs is the . (dot) at the start of the reg/serial.
Not just one, but sometimes two.
So, I took them out. With regex.
Why in the world use that to do that?
Well, because the 'version' of JavaScript in Node-RED does not support the .replaceALL(".", "") function and the .replace(".", "") command only replaces the first . not any after.
So, hence regex.
You have a problem.
That is in my quote doc. Accurate and true.
Here is what I did (don't be tbg, don't do this).
msg.irdm.reg.replace(/./g, "");
This replaces the whole string with "" because in regex the . means any character in any position (or something like that). The 'g' by the way means 'global'. So do the replacement for the whole string.
So the registration simply becomes blank.
Site breaking?
Well, not quite, recall in that first rant blog I mention that I actually make I think about 4 versions of the registration with - and 0 and stuff added and subtracted?
Well, sure, I blanked out one of the combos that I would test against, but did not blank out all of them.
BUT, to fall on my code sword... the first combo was the most likely to match what is in the ADSB community database... So I really took Iridium down a notch on the site search... the very thing I did NOT want to do.
The fix? Make the regex escape the . Like this:
msg.irdm.reg.replace(/\./g, "");
If you recall my first Iridium blog (ok, lets call it what it was, a rant) mentioned about how mangled the irdm rego can be, here the mangle in the cross hairs is the . (dot) at the start of the reg/serial.
Not just one, but sometimes two.
So, I took them out. With regex.
Why in the world use that to do that?
Well, because the 'version' of JavaScript in Node-RED does not support the .replaceALL(".", "") function and the .replace(".", "") command only replaces the first . not any after.
So, hence regex.
You have a problem.
Regex is the answer.
Now you have two problems.
That is in my quote doc. Accurate and true.Here is what I did (don't be tbg, don't do this).
msg.irdm.reg.replace(/./g, "");
This replaces the whole string with "" because in regex the . means any character in any position (or something like that). The 'g' by the way means 'global'. So do the replacement for the whole string.
So the registration simply becomes blank.
Site breaking?
Well, not quite, recall in that first rant blog I mention that I actually make I think about 4 versions of the registration with - and 0 and stuff added and subtracted?
Well, sure, I blanked out one of the combos that I would test against, but did not blank out all of them.
BUT, to fall on my code sword... the first combo was the most likely to match what is in the ADSB community database... So I really took Iridium down a notch on the site search... the very thing I did NOT want to do.
The fix? Make the regex escape the . Like this:
msg.irdm.reg.replace(/\./g, "");
So now we drop all . no matter how many there are in the string.
And guess what?
The number of Iridium messages on the site is rising.
I'll now go stand in a corner and think about what I did.
And guess what?
The number of Iridium messages on the site is rising.
I'll now go stand in a corner and think about what I did.
Comments
Post a Comment