Skip to content

Instantly share code, notes, and snippets.

@HelloWorld017
Last active April 5, 2017 01:18
Show Gist options
  • Select an option

  • Save HelloWorld017/51489d135bebc51b884541ec432b5d2b to your computer and use it in GitHub Desktop.

Select an option

Save HelloWorld017/51489d135bebc51b884541ec432b5d2b to your computer and use it in GitHub Desktop.
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