Discuss Scratch
- Discussion Forums
- » Suggestions
- » RegEx pattern building blocks. (read fully)
- Greg8128
-
500+ posts
RegEx pattern building blocks. (read fully)
Understanding pattern matching (especially through RegEx) is extremely important, and it would be nice if Scratch could support it. However, a blocks such as:
Instead, I would like to propose an implementation where RegEx patterns are constructed using special blocks. These blocks would have a special shape to indicate that they can be put in a place where a valid RegEx pattern is needed.
RegEx pattern blocks:
Any of those blocks (and only any of those blocks) could then be put into the first slot of the following block:
This is my proposal for making RegEx easy to use in Scratch by allowing RegEx patterns to be built from blocks. If you're not sure, try a proof of concept for yourself at: https://snap.berkeley.edu/project?user=gregory8128&project=Regexp%20building%20blocks%20test
(regular expression [^(0|1)*$] matches string [01101]? ::operators)would not be a good fit for Scratch. The reason is that writing out a regular expression is like writing out a text-based program. There is syntax which must be remembered, and syntax errors which must be resovled.
Instead, I would like to propose an implementation where RegEx patterns are constructed using special blocks. These blocks would have a special shape to indicate that they can be put in a place where a valid RegEx pattern is needed.
RegEx pattern blocks:
([r] zero or more times ::#cc0066) // "(r)*" The rectangle slot can accept a string or a RegEx block.
([r] or [s]::#cc0066) // "(r|s)". Both slots can accept strings and RegEx blocks.
(any [character v]::#cc0066) // options include: any character, any letter, any digit, etc. Stands in for ".", "[A-z]" "\s", "\d", etc.
(letter in [r]::#cc0066) // "[r]". 'r' must be a string.
(letter not in [r]::#cc0066) //"[^r]". 'r' must be a string.
([r] then [s]::#cc0066) //"rs". r can be either a string or a RegEx. same with s.
([r] from (x) to (y) times::#cc0066) //r{x,y}. R is a string or a RegEx. x and y are numbers.
(string start::#cc0066) //"^"
(string start::#cc0066) //"$"
Any of those blocks (and only any of those blocks) could then be put into the first slot of the following block:
(regular expression () matches string []? ::#cc0066)The example at the start would then look like this:
(regular expression ((string start::#cc0066) then ((([0] or [1]::#cc0066) zero or more times ::#cc0066) then (string end::#cc0066)::#cc0066)::#cc0066) matches string [01101]? ::#cc0066)
This is my proposal for making RegEx easy to use in Scratch by allowing RegEx patterns to be built from blocks. If you're not sure, try a proof of concept for yourself at: https://snap.berkeley.edu/project?user=gregory8128&project=Regexp%20building%20blocks%20test
Last edited by Greg8128 (Feb. 23, 2021 02:39:43)
- Prime689
-
1000+ posts
RegEx pattern building blocks. (read fully)
Scratch is supposed to be an introductory language, I'm not sure that minors will understand the functionality of this.
- Prime689
-
1000+ posts
RegEx pattern building blocks. (read fully)
Lightnin is talking about the output, not the input. How would it function in using the parameters?I suggest that you read Scratch is supposed to be an introductory language, I'm not sure that minors will understand the functionality of this.this sticky before no supporting due to something being “too complex”
- Greg8128
-
500+ posts
RegEx pattern building blocks. (read fully)
Lightnin is talking about the output, not the input. How would it function in using the parameters?I suggest that you read Scratch is supposed to be an introductory language, I'm not sure that minors will understand the functionality of this.this sticky before no supporting due to something being “too complex”
Could you elaborate on what you mean by that?
If you mean “What does a RegEx engine do?”, then the idea of what RegEx does is relatively simple. You could probably sum it up in a short youtube video.
If you mean “How does a RegEx engine work?”, there are several different implementations and all of the good ones are relatively complex.
- Prime689
-
1000+ posts
RegEx pattern building blocks. (read fully)
Like, how would it operate?Lightnin is talking about the output, not the input. How would it function in using the parameters?I suggest that you read Scratch is supposed to be an introductory language, I'm not sure that minors will understand the functionality of this.this sticky before no supporting due to something being “too complex”
Could you elaborate on what you mean by that?
If you mean “What does a RegEx engine do?”, then the idea of what RegEx does is relatively simple. You could probably sum it up in a short youtube video.
If you mean “How does a RegEx engine work?”, there are several different implementations and all of the good ones are relatively complex.
- -Crlxx-
-
100+ posts
RegEx pattern building blocks. (read fully)
No support
These blocks are to complicated Scratch is supposed to be a simple blocky website. Young children wont understand these blocks. Even I kinda dont understand some of these blocks.
These blocks are to complicated Scratch is supposed to be a simple blocky website. Young children wont understand these blocks. Even I kinda dont understand some of these blocks.
- ScratchCatHELLO
-
1000+ posts
RegEx pattern building blocks. (read fully)
This might be an interesting feature, so maybe support (as an extension). I'm not sure yet about this. I'm going to wait for some more points of view before making up my mind. I think if this is added, it might make sense as an extension so that new scratchers don't get confused because of the complexity of these blocks.
- Greg8128
-
500+ posts
RegEx pattern building blocks. (read fully)
No support
These blocks are to complicated Scratch is supposed to be a simple blocky website. Young children wont understand these blocks. Even I kinda dont understand some of these blocks.
That's exactly why it should be added into Scratch. Young children don't understand things like the “repeat until” loop at first, but Scratch's block-based interface makes it easier to understand that concept. Likewise, it would be easier to learn RegEx if you could make and test a RegEx pattern using easy-to-understand blocks.
- -Crlxx-
-
100+ posts
RegEx pattern building blocks. (read fully)
Ture. In that case it sould be an extension. Because I don't think most people would use itNo support
These blocks are to complicated Scratch is supposed to be a simple blocky website. Young children wont understand these blocks. Even I kinda dont understand some of these blocks.
That's exactly why it should be added into Scratch. Young children don't understand things like the “repeat until” loop at first, but Scratch's block-based interface makes it easier to understand that concept. Likewise, it would be easier to learn RegEx if you could make and test a RegEx pattern using easy-to-understand blocks.
- PkmnQ
-
1000+ posts
RegEx pattern building blocks. (read fully)
This isn't even the full power of regex you can get from JS. There are backreferences and lookarounds, and that's not even mentioning what PCRE can do, but I'd call the subset you chose a good subset for Scratch.
- Greg8128
-
500+ posts
RegEx pattern building blocks. (read fully)
I made a mockup of what a RegEx extension for Scratch might look like: https://snap.berkeley.edu/project?user=gregory8128&project=Regexp%20building%20blocks%20test
It's implemented as a set of custom reporters, one for checking whether a RegEx pattern matches a string, and the others for putting together RegEx patterns from blocks. It's not perfect, but it should give you a rough idea of how a RegEx extension would be used.
It's implemented as a set of custom reporters, one for checking whether a RegEx pattern matches a string, and the others for putting together RegEx patterns from blocks. It's not perfect, but it should give you a rough idea of how a RegEx extension would be used.
- fdreerf
-
1000+ posts
RegEx pattern building blocks. (read fully)
A way of implementing RegEx that is both powerful to use and much easier for beginners to understand? Yum yum.
I still think that the terms for the blocks might be a little too abstract for most, but you could easily hide it in an extension and nobody will care.
I still think that the terms for the blocks might be a little too abstract for most, but you could easily hide it in an extension and nobody will care.
- Socialix
-
1000+ posts
RegEx pattern building blocks. (read fully)
Semi-support. A kid will sneak in the extensions page and put the RegEx extension not knowing what it is in the coding class. Then, the teacher will ground the child for putting an extension the teacher didn't say.
I don't even know what and how RegEx's work, but adding a tutorial could fix the problem. It feels too advanced, but okay.
I don't even know what and how RegEx's work, but adding a tutorial could fix the problem. It feels too advanced, but okay.
- Greg8128
-
500+ posts
RegEx pattern building blocks. (read fully)
The first problem isn't related to the extension imo. As for the second problem, that is kind of why this suggestion should be added. Using regular expressions is a lot like using programming languages*. Just like Scratch makes it easy to learn programming by getting the syntax out of the way, this suggestion would also get the syntax out of the way of learning about the capabilities of RegEx. Semi-support. A kid will sneak in the extensions page and put the RegEx extension not knowing what it is in the coding class. Then, the teacher will ground the child for putting an extension the teacher didn't say.
I don't even know what and how RegEx's work, but adding a tutorial could fix the problem. It feels too advanced, but okay.
*Most programming languages are designed around computers equivalent to a Turing machine. Regular Expressions, meanwhile, are basically tools for “programming” finite-state machines, which are simpler but capable of solving a narrower range of problems (such as pattern matching). Basically, regular expressions are a very simple kind of programming language. Study formal language theory to learn more about this topic.
- the2000
-
1000+ posts
RegEx pattern building blocks. (read fully)
Congratulations Socialix, you have reached levels of paranoia and irrationality not previously believed to be humanly possible. Semi-support. A kid will sneak in the extensions page and put the RegEx extension not knowing what it is in the coding class. Then, the teacher will ground the child for putting an extension the teacher didn't say.
Seriously, how is this the fault of the suggestion at all?
- sathvikrias
-
500+ posts
RegEx pattern building blocks. (read fully)
NO SUPPORT. I have been on scratch for like, more than a year,(this is a alt account see @hearst10), I have even been on snap for at least 3 months and I would NEVER understand this.
- PGBFLITE6373
-
1000+ posts
RegEx pattern building blocks. (read fully)
Me neither but SOmeone like griffpstch would love to use this, ANd i could prob learn this in a day NO SUPPORT. I have been on scratch for like, more than a year,(this is a alt account see @hearst10), I have even been on snap for at least 3 months and I would NEVER understand this.
- sathvikrias
-
500+ posts
RegEx pattern building blocks. (read fully)
maybe… Me neither but SOmeone like griffpstch would love to use this
yeah thats impossible ANd i could prob learn this in a day
- the2000
-
1000+ posts
RegEx pattern building blocks. (read fully)
I program in JavaScript and my best understanding of RegEx is currently just “copy and paste from the internet and hope it works.” That's probably my own fault more than anything thoughyeah thats impossible ANd i could prob learn this in a day

- Discussion Forums
- » Suggestions
-
» RegEx pattern building blocks. (read fully)