Discuss Scratch
- Discussion Forums
 - » Suggestions
 - » PCRE reporter
        
         
- 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
I had to do this
When it could be done with one reporter block
So I'd love a PCRE reporter or a Regex reporter so I don't have to deal with these by myself.
                        
                        
                    /^#?([a-f0-9]{6}|[a-f0-9]{3})$/iset [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) // 0So 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:
(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.
                        
                            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, GoLangIn 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
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
/(positive/negative) (lookahead|lookbehind)s?/gi
Last edited by RedGuy7 (Dec. 24, 2020 03:08:18)
- RedGuy7
 - 
                            
						
						
                            Scratcher
                        
						
						 
1000+ posts
PCRE reporter
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)
- sealifefriend
 - 
                            
						
						
                            Scratcher
                        
						
						 
500+ posts
PCRE reporter
*blinks* *blinks again* huh? does scratch really need those…?
                        
                        
                    - PkmnQ
 - 
                            
						
						
                            Scratcher
                        
						
						 
1000+ posts
PCRE reporter
*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]Big script.
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
Now look at the regex:
/^#?([a-f0-9]{6}|[a-f0-9]{3})$/iLast 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.
                        
                        
                    - 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.
                        
                        
                    - 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.
                        
                        
                    However, I totally support APIs, which should be easier to implement.
- RedGuy7
 - 
                            
						
						
                            Scratcher
                        
						
						 
1000+ 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.Js has it's own built in parser…
However, I totally support APIs, which should be easier to implement.
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
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
Here's a better tutorial. It's actually linked in the regex101 quiz.I feel stupid, but may I get an in-depth explanation of what exactly this does????????Bottom right corner
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.
- Discussion Forums
 - » Suggestions
 - 
            » PCRE reporter 
         
            









