You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have written a script that interprets the selected text as a RegExp, and replaces fullText with the text matched by the regexp joined with newlines, but I can't get it to work.
/** { "api":1, "name":"Regex select", "description":"Use selection as regex input, removes it from the input and then returns all matches", "author":"piero512", "icon":"quote", "tags":"boop,state,script,debug,new,create" }**/functionremoveRegexInput(selected,text){returntext.replace(selected,'');}functioncopyRegexMatches(regexp,text){returntext.match(regexp);}functionmain(input){try{if(!input.isSelection){input.postError('You have to select something before calling this script!');}else{varcopy_selection=input.selection;varremovedRegex=removeRegexInput(input.selection,input.fullText);varregexp=RegExp(copy_selection,'gm');varmatches=copyRegexMatches(regexp,removedRegex);varnewText=matches.join('\n');console.log(newText);input.fullText=newText;}}catch(e){input.postError("Unknown error: "+e.toString());}}
The text was updated successfully, but these errors were encountered:
Well, I should have added what was wrong. The else branch runs when there is a selection (as is), but the expected behavior is to replace the text in the window completely with the newText var but it just doesn't work for me 😢,nor it throws exceptions.
I have written a script that interprets the selected text as a RegExp, and replaces fullText with the text matched by the regexp joined with newlines, but I can't get it to work.
The text was updated successfully, but these errors were encountered: