Regular Expressions! #166
Replies: 21 comments
-
Posted at 2017-10-10 by @allObjects That's excellent... (I often wonder where you still find the memory for it...). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-10 by @gfwilliams I'm sure it'll make the builds for the original Espruino a little more painful, but it's worth it - and not actually that much more code (it's not a 100% full-featured regex, but should be enough for basic stuff) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-10 by PaddeK Are functions as replacement supported? I would love to be able to use my RunlengthEncoding snippets.
-- Edit -- |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-11 by @gfwilliams edit: function replacements are now supported! I'm afraid you can't use functions for replacement at the moment - and also there aren't backreferences so your encoder wouldn't work. The code would work but would insert the stringified function - hence lack of memory :) I'll see about adding the functions - that shouldn't be too hard. Backreferences are possible, but a reasonable amount of work - I wonder how often they're used. While your RLE code is neat, it's pretty easy and possibly faster to implement in normal JS :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-11 by PaddeK Funny you say that.. i did just rewrite it in normal JS.. but it is not ready yet. Sadly i already minified it because it worked in the browser and with node js. But with espruino it seems to hang up somewhere. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-11 by @gfwilliams But it works when unminified? If you find out where it behaves differently, please can you let me know? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-11 by PaddeK I did not test it unminified. Let me try that later today and i will let you know if anything changes. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-11 by @gfwilliams Just added the ability to use functions (only for regex though) - but you still don't get backreferences I'm afraid. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-11 by @allObjects That was the thing I used in the past (replace with context logic).
Is this referring to |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-11 by PaddeK Thanks @gordon i will give it a try. I am in the process of deminifying my RLE implementation. In my case i only need the backreferences for encoding.. which is a pre step on the PC. I only need the decoding part on the espruino. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-11 by PaddeK Okay here are the results in respect of RLE. First the two contenders: Unminified
Minified
I minify by hand but i tested the code in the browser and nodejs and confirmed both versions work as expected. It is not a straight RLE implementation as you can see.. the purpose is to minify base64 strings, so there is some substitution going on. In regard to espruino the unminfied version is running fine. The minified version however behaves unexpected. The webIDE freezes.. reconnecting to the board does not work, even typing on the left side is not working. Restarting the webIDE has no effect. I have to reflash my espruino wifi to fix this. -- Edit --
I get the same behaviour as with my minified non regex version. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-12 by @gfwilliams Do you have any example input/output? You said it needed base64? Also, there's actually a good compressor called |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-12 by @gfwilliams If you try the latest build, it should work now:
It turns out it was because |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-12 by PaddeK It would need base64 as input for the encoding and the result of that is input for the decoding. To give a little background.. i recently got a eink display (waveshare 4.2 inch) and i wanted to display full size (400x300) images with espruino. The output of the common img2lcd tool was Having any compression/decompression options build in would be nice and if the output of the compression could be an accepted string would be nice for assets. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-12 by PaddeK For my test input of 5310 chars it still crashes.
Here is the full example code to reproduce:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-12 by @gfwilliams Ahh - it's almost certainly a problem with the upload. There are some huge hacks in the Web IDE to try and add support for non-ascii characters in strings. Since you're only using base64, can you find a few extra characters that have character codes less than 128? http://www.asciitable.com/ |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-12 by PaddeK I will give that a try.. i did choose the current characters so i can use that mod 10 hack :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-12 by PaddeK With the new encoding it doesn't crash.. but it returns after quite some while.. about 15min+ with a wrong result. Thats odd :D To not further spam this forum with huge encoded data i created |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-06 by jijidad Does the Espruino implementation of RegEx support the | "or" operator? Simplest test case:
Here I'm getting back false... [MDBT42Q 1v99] |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-07 by @gfwilliams No, I'm afraid it doesn't at the moment. I'll file an issue for it. You'll either have to use two regexes, or in the case you have there, use |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-27 by @gfwilliams
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-10-10 by @gfwilliams
There are now finally regular expressions in Espruino! If you download a cutting edge build then you should get them.
There's:
/regex/
syntax to define themregex.exec
to match on a supplied stringstring.replace(regex, replacement)
string.split(regex)
It's not got all the RegEx functionality built in, but should cover most of the common use-cases.
Let me know how it goes! The RegEx system might still need some work, so if you find a RegEx that doesn't seem to be working properly, please let me know!
Beta Was this translation helpful? Give feedback.
All reactions