Skip to content

Conversation

@ScratchFakemon
Copy link
Contributor

@ScratchFakemon ScratchFakemon commented Oct 22, 2025

Added modified versions of split and matchRegex that both return an array instead of a specific item, which can be useful in more complex projects. I also moved testRegex so all of the match blocks could be together in the palette.

Pretty quick, so there isn't that much polish. It was mostly an easy copy-and-paste job and things are still left in.

Added modified versions of split and matchRegex that return an array instead of a specific item, which can be useful in more complex projects.
@github-actions github-actions bot added the pr: change existing extension Pull requests that change an existing extension label Oct 22, 2025
@ScratchFakemon ScratchFakemon marked this pull request as draft October 22, 2025 19:48
@ScratchFakemon
Copy link
Contributor Author

Converted to draft so I could fix some things

@ScratchFakemon
Copy link
Contributor Author

There we go

@ScratchFakemon ScratchFakemon marked this pull request as ready for review October 22, 2025 19:50
@ScratchFakemon ScratchFakemon changed the title Add splitJSON and matchRegexJSON strings: Add splitJSON and matchRegexJSON Oct 24, 2025
@ScratchFakemon
Copy link
Contributor Author

To be honest, it's kind of weird that these weren't already in the extension. It's no stranger to more complex features like regexes, which Scratch's target audience wouldn't have much of a grasp on. There are, in fact, genuine use cases for these new blocks—I made these changes to benefit one of my own projects with hopes of making a script much faster than using loops and variables.

@ScratchFakemon
Copy link
Contributor Author

Yeah it's safe to say no one's gonna review this pr for a while

@Brackets-Coder
Copy link
Contributor

Alright wish granted

Copy link
Contributor

@Brackets-Coder Brackets-Coder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax looks fine I guess, nothing jumps out just a quick skim

For the split JSON block, is the intended functionality to leave blank elements where the split was or remove everything except the split

e.g., "apple" split by "p" returns ["a","","le"], did you mean to remove the blank middle item?

Another concern I have—do the "regex" inputs accept RegEx blocks from the RegEx extension? Those return strings, so you might want to find ways to parse the strings back into actual JS regex

@ScratchFakemon
Copy link
Contributor Author

I just copied the existing split and matchRegex blocks and just made them return the whole array, so the functionality should match the existing blocks. There isn't anything special going on. Like I said, it's unpolished and kind of hacked together.

(I also have no idea how regexes work sooooo time to go learn stuff ig)

@Brackets-Coder
Copy link
Contributor

I just copied the existing split and matchRegex blocks and just made them return the whole array, so the functionality should match the existing blocks. There isn't anything special going on. Like I said, it's unpolished and kind of hacked together.

(I also have no idea how regexes work sooooo time to go learn stuff ig)

https://www.w3schools.com/js/js_regexp.asp

@ScratchFakemon
Copy link
Contributor Author

ScratchFakemon commented Nov 8, 2025

Syntax looks fine I guess, nothing jumps out just a quick skim

For the split JSON block, is the intended functionality to leave blank elements where the split was or remove everything except the split

e.g., "apple" split by "p" returns ["a","","le"], did you mean to remove the blank middle item?

Another concern I have—do the "regex" inputs accept RegEx blocks from the RegEx extension? Those return strings, so you might want to find ways to parse the strings back into actual JS regex


I just copied the existing split and matchRegex blocks and just made them return the whole array, so the internal workings should match the existing blocks. There isn't anything special going on. Like I said, it's unpolished and kind of hacked together.

(I also have no idea how regexes work sooooo time to go learn stuff ig)

In short, the new blocks are based on the existing ones, so the way they work matches.
The existing split block also matches the described behavior—it's item 3 of apple split by p (where the array is 1-indexed to match list behavior).

matchRegexJSON also only supports the RegExp extension in the same way the original matchRegex does:
Original block: block_11_8_2025-8_11_49 AM
New block: block_11_8_2025-8_15_16 AM

@Brackets-Coder
Copy link
Contributor

Wait so if the functionality is the same what actually changed?

@ScratchFakemon
Copy link
Contributor Author

Wait so if the functionality is the same what actually changed?

I only changed it so it returned the whole (stringified) array instead of a single item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: change existing extension Pull requests that change an existing extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants