Discuss Scratch

MySuggestNot2Hard21
New Scratcher
25 posts

PCRE reporter

As a Scratcher, I find matching some text too hard and it requires too much loop, for example when I try matching this PCRE pattern
/^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
I had to do this
set [matches v] to [0]
set [i v] to [1]
if <(letter (1) of (pattern)) = [#]> then
set[i v] to [2]
end
if <<((length of (pattern)) - ((i) - (1))) = [6]> or <((length of (pattern)) - ((i) - (1))) = [3]>> then
set [matches v] to [1]
repeat ((length of (pattern)) - ((i) - (1)))
if <not <(letter (i) of (pattern)) contains [0123456789abcdef]:: operators>> then
set [matches v] to [0]
end
change [i v] by (1)
end

When it could be done with one reporter block
(PCRE matches (/[^#?\([a-f0-9\]\{6}|[a-f0-9\]\{3})$]/[i]:: extension) [7f7f7f] ::extension) // 1
(PCRE matches (/[^#?\([a-f0-9\]\{6}|[a-f0-9\]\{3})$]/[i]:: extension) [scratch] ::extension) // 0

So I'd love a PCRE reporter or a Regex reporter so I don't have to deal with these by myself.
RedGuy7
Scratcher
1000+ posts

PCRE reporter

What flavor would it use? I think it should have a dropdown, although it might just use ECMAScript since that what JavaScript uses and Scratch is coded in JavaScript. although to be PCRE compatible it would have to be Pearl flavor.
It'd either go in operators or a new RegEx extension.
See also my tweaks to these blocks:
RegEx [] ()th match [Pearl v] flavor :: operators //also available: ECMAScript, Python, GoLang
RegEx [] all matches [Pearl v] flavor to list [lists v] :: operators // would return all matches into a list selected with the last dropdown
RegEx [] result count [Pearl v] flavor :: operators
In JS or PHP, using matching groups () creates a multidimensional array. I don't know how that would work since we don't have and will never have multidimensional arrays on scratch. I guess you could only return the “full matches”. You'd have to do separate RegExes and
/(positive/negative) (lookahead|lookbehind)s?/gi
(yes that's a RegEx) for the others. You just couldn't put quantifiers in them. Alternatively you could just stuff them all into the same list.

Last edited by RedGuy7 (Dec. 24, 2020 03:08:18)

mybearworld
Scratcher
1000+ posts

PCRE reporter

What would this do?
RedGuy7
Scratcher
1000+ posts

PCRE reporter

mybearworld wrote:

What would this do?
regular expressions are a bit complicated. google them, they're used in other programming languages a lot

edit: here regular expression

Last edited by RedGuy7 (Dec. 24, 2020 02:39:26)

PkmnQ
Scratcher
1000+ posts

PCRE reporter

mybearworld wrote:

What would this do?
It's a regex. They can detect stuff in text. Especially PCRE, which is apparently Turing-Complete. Here's a PCRE regex that detects correctly nested parentheses.
sealifefriend
Scratcher
500+ posts

PCRE reporter

*blinks* *blinks again* huh? does scratch really need those…?
PkmnQ
Scratcher
1000+ posts

PCRE reporter

sealifefriend wrote:

*blinks* *blinks again* huh? does scratch really need those…?
To detect hex colors without PCRE, you have to use this:
set [matches v] to [0]
set [i v] to [1]
if <(letter (1) of (pattern)) = [#]> then
set[i v] to [2]
end
if <<((length of (pattern)) - ((i) - (1))) = [6]> or <((length of (pattern)) - ((i) - (1))) = [3]>> then
set [matches v] to [1]
repeat ((length of (pattern)) - ((i) - (1)))
if <not <(letter (i) of (pattern)) contains [0123456789abcdef]:: operators>> then
set [matches v] to [0]
end
change [i v] by (1)
end
Big script.

Now look at the regex:
/^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
Small regex.

Last edited by PkmnQ (Dec. 24, 2020 02:57:44)

Greg8128
Scratcher
500+ posts

PCRE reporter

Regex is pretty difficult to use and is basically a text-based language. IMO making a pattern matcher by hand is easier to understand for beginners and also a better learning experience.
Basic88
Scratcher
1000+ posts

PCRE reporter

This block is kind of complex. No support.
pavcato
Scratcher
1000+ posts

PCRE reporter

This seems way too complex for a programming language made for people who have never coded. This is something I'd expect in Snap, but definitely not on Scratch.
Hearst10
Scratcher
100+ posts

PCRE reporter

no support. way too complicated.
mybearworld
Scratcher
1000+ posts

PCRE reporter

Basic88 wrote:

This block is kind of complex. No support.
themasterofme
Scratcher
71 posts

PCRE reporter

I don't think the feature is usable with so much lexing, parsing and stuff. The ST doesn't have time to implement their own parser for that.
However, I totally support APIs, which should be easier to implement.
RedGuy7
Scratcher
1000+ posts

PCRE reporter

themasterofme wrote:

I don't think the feature is usable with so much lexing, parsing and stuff. The ST doesn't have time to implement their own parser for that.
However, I totally support APIs, which should be easier to implement.
Js has it's own built in parser…
APIs are completely different.
gosoccerboy5
Scratcher
1000+ posts

PCRE reporter

I feel stupid, but may I get an in depth explanation of what exactly this does????????
RedGuy7
Scratcher
1000+ posts

PCRE reporter

gosoccerboy5 wrote:

I feel stupid, but may I get an in depth explanation of what exactly this does????????
Bottom right corner

Last edited by RedGuy7 (Dec. 26, 2020 03:39:44)

PkmnQ
Scratcher
1000+ posts

PCRE reporter

RedGuy7 wrote:

gosoccerboy5 wrote:

I feel stupid, but may I get an in-depth explanation of what exactly this does????????
Bottom right corner
Here's a better tutorial. It's actually linked in the regex101 quiz.

pavcato wrote:

This seems way too complex for a programming language made for people who have never coded. This is something I'd expect in Snap, but definitely not on Scratch.
Well, if it's too complicated, they just won't use it.

Powered by DjangoBB