Discuss Scratch

Ihatr
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

sathvikrias wrote:

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.
Try to learn it before you just no-support it.
gosoccerboy5
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Ihatr wrote:

sathvikrias wrote:

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.
Try to learn it before you just no-support it.
Let's add Scheme and C+ and BranFlakes to Scratch! Before you no-support, though, try to learn them.

Sorry @Greg8128 but I seriously have no idea how this works, so unless this appeals to more advanced users on Scratch than I originally thought, barely a semi-support because I don't see the majority of users understanding this either, but I could be wrong.
fdreerf
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Perhaps instead of dismissing the suggestion as too advanced, we could tweak it so that the suggestion itself helps teach RegEx. After all, we were all once completely unfamiliar with every block in Scratch, and yet it was great for teaching more advanced programming.
Greg8128
Scratcher
500+ posts

RegEx pattern building blocks. (read fully)

fdreerf wrote:

Perhaps instead of dismissing the suggestion as too advanced, we could tweak it so that the suggestion itself helps teach RegEx. After all, we were all once completely unfamiliar with every block in Scratch, and yet it was great for teaching more advanced programming.

Two changes that I though of:
1. patterns match the entire string by default, not just some part of it. (so basically it is like there is always a “^” at the start and a “$” at the end). Thre could be a different block to match patterns inside of a string.

2. The addition of the following block:
(something in [list v] ::#cc0066)
, which constructs a pattern matching anything in the given list. (I tried to add an example but it overflowed the box boundaries. Maybe the block names should be more concise)
To make sure that the player chooses an “authentic” name for his or her dwarf character.
(RegEx can't do this by itself, but it can be done by making a function write out the RegEx pattern for you. Which is basically what these blocks do.)

These ideas might be not very good. I have a decent understanding of RegEx, so it is hard for me to truly “get in the shoes” of someone who does not. So tell me what you find confusing about RegEx and what you would like to learn about it.

Last edited by Greg8128 (Feb. 26, 2021 08:14:12)

PkmnQ
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Definitely best as an extension. Pen usually isn't necessary for projects, but when you need it, you can put that extension in. Same for this one.
gosoccerboy5
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Bump.
Having learned some about Regexps, they seem like a really useful tool. I'll look into this more
gosoccerboy5
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Greg8128 wrote:

(regular expression () matches string []? ::#cc0066)
I might also add:
(replace () in [] with []::#cc0066) //first input should accept regex or text
ScratchCatHELLO
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Socialix wrote:

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.

excuse me but what does this have to do with anything? what teacher is going to ground a student for doing something slightly different from their instructions? actually, how does a teacher ground a student? actually, what teacher is going to be upset with the student for learning about the subject?

I actually think I'll full support this because it teaches a useful feature of programming languages in an understandable way. I don't know how many people would use this, but for those people it would be useful/interesting.
gosoccerboy5
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Socialix wrote:

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.
Why is that grounds for a grounding*? Putting in a random extension is harmless.
How likely is this to happen anyways?
And how does that outweigh the potential benefits to Scratch?
ALSO, cant they do that with current extensions?

*terrible pun intended

Last edited by gosoccerboy5 (May 17, 2021 16:14:57)

imfh
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

I would suggest a slightly different style, and some more ideas for potential matching blocks. For the blocks below, “re” could be replaced by the extension's icon. Edit: To clarify, these are in addition to the pattern blocks in the OP.

returns true if the pattern matches anywhere in the string ::grey
<re pattern [[a-z\].+?] matches [text]? ::extension> // returns true
gives the position of the first occurrence of pattern in the string ::grey
(re find [\d{3}] in [abc123] ::extension) // returns 4
gives the number of matches found in text ::grey
(re count [\\b\\w\\b] in [hello there] ::extension) // returns 2
replaces each match with text, supports capture groups using $0 notation ::grey
(re replace [\\b([b-df-hj-np-tv-xz\]{1,2})(\\w+?)\\b] in [hello there!] with [$2$1ay] ::extension) // returns "ellohay erethay!"
also, this new pattern block should be added ::grey
(re escape [What is your name?] ::extension) // returns "What is your name\?"

I would also like to point how useful regex blocks could be, particularly the replace block:

substring [hello there] (3) (9) // returns "lo the"

define substring (text) (from) (to)
set [return v] to (re replace (join [(?s).*{] (join (from) (join [}(.+{] (join ((to)-(from)) [}).*])))) in (text) with [$1] ::extension)

Edit: Fixed some typos I noticed on a later read and changed the first block slightly.

Last edited by imfh (May 18, 2021 17:41:43)

sathvikrias
Scratcher
500+ posts

RegEx pattern building blocks. (read fully)

-∞ support. (negative infinity) scratch is meant as a INTRODUCTION to programming. this is too complicated and would rarely be used.
Greg8128
Scratcher
500+ posts

RegEx pattern building blocks. (read fully)

sathvikrias wrote:

-∞ support. (negative infinity) scratch is meant as a INTRODUCTION to programming. this is too complicated and would rarely be used.
Now it can be an introduction to RegEx too! RegEx's are easy to use and extremely useful once you understand what they are, and this suggestion could really help demystify RegEx for beginners.
PkmnQ
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

sathvikrias wrote:

-∞ support. (negative infinity) scratch is meant as a INTRODUCTION to programming. this is too complicated and would rarely be used.
RegEx is a simpler form of programming that's often feared for some reason I don't understand (unless it's PCRE). I'd say it'd be fine to include.

Last edited by PkmnQ (May 18, 2021 17:09:44)

fdreerf
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

imfh wrote:

I would suggest a slightly different style, and some more ideas for potential matching blocks. For the blocks below, “re” could be replaced by the extension's icon.
I have a few gripes with these, mainly you have to actually type out the regular expression. It sort of goes against the spirit of Scratch; instead of learning the structure and how to build one, you just kind of memorize cryptic text, and you can't see all the options you have at your disposal nor try them all out and see what they do. While not necessarily a bad thing, I think having blocks and “building” a regex would be better suited for Scratch.

Last edited by fdreerf (May 18, 2021 17:30:07)

PkmnQ
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

fdreerf wrote:

imfh wrote:

I would suggest a slightly different style, and some more ideas for potential matching blocks. For the blocks below, “re” could be replaced by the extension's icon.
I have a few gripes with these, mainly you have to actually type out the regular expression. It sort of goes against the spirit of Scratch; instead of learning the structure and how to build one, you just kind of memorize cryptic text, and you can't see all the options you have at your disposal nor try them all out and see what they do. While not necessarily a bad thing, I think having blocks and “building” a regex would be better suited for Scratch.
I think he meant the blocks would still exist but also with the new proposal.
imfh
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

PkmnQ wrote:

fdreerf wrote:

imfh wrote:

I would suggest a slightly different style, and some more ideas for potential matching blocks. For the blocks below, “re” could be replaced by the extension's icon.
I have a few gripes with these, mainly you have to actually type out the regular expression. It sort of goes against the spirit of Scratch; instead of learning the structure and how to build one, you just kind of memorize cryptic text, and you can't see all the options you have at your disposal nor try them all out and see what they do. While not necessarily a bad thing, I think having blocks and “building” a regex would be better suited for Scratch.
I think he meant the blocks would still exist but also with the new proposal.
Yes, I'm suggesting these as an addition to the pattern blocks in the OP. I don't think regex would be very useful with just a boolean match block, so adding a find position, count matches, and replace matches with block would add a lot more functionality.

Edit: Looking at the OP again, it looks sort of like it is suggesting that only pattern blocks can be put into the pattern slot of regex blocks. I would suggest you can also manually type out regular expressions if this is the case.

Last edited by imfh (May 18, 2021 17:43:57)

gosoccerboy5
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Ahh.. my old posts here were so cringey..
anyways bump
badatprogrammingibe
Scratcher
500+ posts

RegEx pattern building blocks. (read fully)

No support:
Implementing regular expressions is an incredible learning exercise that will teach you a lot about computer science.
gosoccerboy5
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Would capturing groups be supported? Bump
PenguinLover1123
Scratcher
1000+ posts

RegEx pattern building blocks. (read fully)

Prime689 wrote:

Scratch is supposed to be an introductory language, I'm not sure that minors will understand the functionality of this.
An extension then??????

Powered by DjangoBB