Last active
April 5, 2017 01:18
-
-
Save HelloWorld017/51489d135bebc51b884541ec432b5d2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| new (function() { | |
| var ext = this; | |
| var debugmode = !!window.scratchRegexExtensionEnv; | |
| ext._shutdown = function() {}; | |
| ext._getStatus = function() { | |
| return {status: 2, msg: 'Ready'}; | |
| }; | |
| ext.regex = function(str, regexStr, flags, n){ | |
| if(debugmode) console.log(str, regexStr, flags, n); | |
| try{ | |
| var regex = new RegExp(regexStr, flags); | |
| var match = str.match(regex); | |
| if(debugmode) console.log(match); | |
| if(!match) return -1; | |
| return match[n]; | |
| }catch(e){ | |
| if(debugmode) console.error(e); | |
| } | |
| }; | |
| var descriptor = { | |
| blocks: [ | |
| ['r', '%s 를 / %s / %s 로 매칭한 %n 번째', 'regex', 'Hello', '[a-z]', 'i', 0] | |
| ] | |
| }; | |
| // Register the extension | |
| ScratchExtensions.register('Regex Extension', descriptor, ext); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment