|
As an IoT person, you probably have done a lot of assembly language programming. I find that people who love regex tend to also like assembly (including myself). I find regex very elegant, and immensely powerful.
Da Bomb
|
|
|
|
|
I actually avoid assembly wherever I can. We have so many different MCUs that come along, and supply is questionable sometimes, which means switching chips mid project. I mean, Arm Cortex M to Arm Cortex M it's not the worst thing in the world, but you'd still have all the CMSIS stuff you'd have to deal with.
Ergo, I abstract, and use C++ with ZephyrRTOS for my projects.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
honey the codewitch wrote: I know some people hate them,
I certainly don't hate them since I use them quite a bit.
Of course no one provides a comment for what they are intended to match. Nor how the match works.
But I have seen quite a few that I knew to be wrong. That is concerning.
honey the codewitch wrote: - they are cross platform (at least DFA), running in most any engine
Not sure what you mean by that. The engine that runs the regex is the only 'cross platform' part possible in that. The regex expressions themselves depend only on the engine so the expression itself has nothing to do with the platform.
Perhaps you were referring to that the simplest syntax works in different engines though. But once one uses something more complex that is not necessarily true. But at least with javascript, java and C# they to a great extent use the same syntax.
|
|
|
|
|
jschell wrote: Not sure what you mean by that.
What I mean is that regardless of the platform you choose, there is a way to run a DFA regular expression on it.
And yeah, that encompasses many different engines, which themselves are what run on a particular platform, unless you're doing code generation, which I do sometimes for them so I don't have to include the regex engine in my firmware. That code is easy to make cross platform. You'd almost have to put in extra effort to make it otherwise.
I was maybe trying to be too brief by half. I assumed the meaning would come through, but I guess not.
jschell wrote: Perhaps you were referring to that the simplest syntax works in different engines though
In part yes, but also, virtually every platform has a DFA regex engine for it, or alternatively you can generate DFA code for that platform, with something such as my rxcg project. I was intending to imply that as well.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
honey the codewitch wrote: What I mean is that regardless of the platform you choose, there is a way to run a DFA regular expression on it.
If you find a programming system that doesn't allow that then you might prepare for the universe to end. Far as I can recall it would be mathematically impossible for that not to be true.
|
|
|
|
|
jschell wrote: If you find a programming system that doesn't allow that then you might prepare for the universe to end
Maybe I misunderstand you, but if you're speaking in the general sense, you aren't going to run a garbage collected system for example, on an 8-bit platform with 4KB of RAM, hopefully. Even if you could, it wouldn't be practical for anything. A DFA on the other hand will run handily there.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
honey the codewitch wrote: A DFA on the other hand will run handily there.
Reverse that though. What system, which has resources to run anything that is non-trivial, will not run a DFA?
|
|
|
|
|
I can't think of anything that couldn't run a DFA. It's such a basic Turing-esque construction.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
That is what I meant when I responded to your original comment.
|
|
|
|
|
I use regular expressions regularly.
The downside is that it is difficult for newcomers to understand them. But as long as you add comments to your code it shouldn't be a problem. And many languages allow you to add comments WITHIN the regular expressions, making them even easier to understand. (I frequently create my regexes with comments in C# and then take out the comments afterwards, leaving the original version within commented-out code.)
|
|
|
|
|
Being a compact way to describe something is very much the problem. That is exactly why people hate them. You can't just read one and know what it does, nor expect that of your colleagues. Every time I add a RegEx to the code, I have to add an explanation of what it does.
Just like in code: if it needs comments to be readable, something's very wrong.
|
|
|
|
|
Jeroen_R wrote: if it needs comments to be readable, something's very wrong.
That's true in the general case, but the exceptions are legion.
I'd argue regex is one of those exceptions. There is simply not a more compact and efficient way to tokenize or match flat text than DFA regular expressions.
Sure you could try writing it out, but I have. Try your hand at creating a more verbose language than regex and see what it looks like.
I wrote one that allows you to describe regular expressions using a BNF notation variant. The result required too much typing, let's put it that way, even though BNF is fairly compact as well.
If there's a better mousetrap, nobody seems to have found it yet.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
This is the most runaway thread on CP in a long while. Way to poke the bear.
|
|
|
|
|
I blank out on regular expressions. Too much like learning a new language. The other day, I needed to get 0 or more leading characters from a string (as an int). I Googled (regex), I went, I left.
Coding challenge: get leading digits (I settled for LINQ)
var text = "123rd NY 2nd Battalion".
var count = text.TakeWhile( c => Char.IsDigit( c ) ).Count();
int i = count > 0 ? ConvertToInt32( text.SubString( 0, count) ) : 0;
Answer: 123
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
^[0-9]+
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
i requested ChatGBT "please write a regular expression which identifies the numerical digits beginning a text ."
its response below .
^\d+
is it wrong ? was my request incorrect ?
|
|
|
|
|
It won't identify them, but it'll match them. Getting it to assign that value or print it out involves more code not related to regex.
|
|
|
|
|
i enjoy the challenge of learning / writing regular expressions for my text editing of source code . as in all things mastering it is the same as being invited to perform at Carnegie Hall id est "practice practice practice" . my purpose in this post though is to express my impression from these many and expert posts utilizing fancy schmancy terms of which i do not know which seem to indicate regular expressions are more powerful / advanced / sophisticated than i know as i understand them to be nothing more than a text editing convenience . may i please inquire am i wrong in this regard . thank you kindly .
|
|
|
|
|
They're for text processing, but for more than text editing.
The C# compiler for example, almost certainly uses a tokenizer built up of regular expressions.
That said, you're basically not wrong. I mean, tokenization is almost like text matching, but with a twist.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
If you like to read technical stuff then "Mastering Regular Expressions" by Friedl (yes spelled like that.)
Not only interesting but a bit scary since it provides examples that will shut down your system.
|
|
|
|
|
|
Of course abuse of QR codes is obvious.
QR codes can be phishing scams in disguise, warns the FTC - The Verge[^]
But I encounter this real scenario....
Went to park at a downtown parking lot that I had not parked at for quite some time (pre-covid probably).
Before there used to be credit card reader kiosk. Those have been around for a while.
Now all there is is a sign, rather large one, with a message like 'Use the QR code to pay'. Then of course a QR code.
It is trivially simple to print out a QR code and just cover up the real one. Not even sure in this case that replacing it would require more than just someone that was a bit taller than average.
One could likely do that on quite a few lots in one night.
It would be days or even weeks before anyone figured it out. Even if a diligent check of proceeds from one lot showed reduced revenue I bet figuring out why would take some time and one lot owner would probably just fix their own lots.
And they would be unlikely to rescind tickets, handed out of course because the real QR code wasn't used, unless a government agency started getting involved. Perhaps not even then.
|
|
|
|
|
This.
The only time I've ever read QR codes was to use them as input to an app showing the actual target URL (but NOT actually following it).
Clearly, as you've described, this is ripe for abuse.
|
|
|
|
|
So this lot has an honor system for paying? No gate at the exit that requires some confirmation of payment (ex. a "paid" ticket be inserted / scanned)?
|
|
|
|
|
There has to be more to it than that. Most car parks use ANPR, so the driver would need to connect his payment to the car's index plate in some way.
|
|
|
|