4 ms·
OK, I am an intermediate to advanced BSD sed user. I can do things with only basic regex that I have seen others struggle to do with extended and Perl-compatib
by ised 11y ago
OK, I am an intermediate to advanced BSD sed user. I can do things with only basic regex that I have seen others struggle to do with extended and Perl-compatible regex.
But I am as green as it gets when it comes to Javascript.
I am sometimes forced to use a Windows workstation.
So I installed "super sed" (ssed.exe), a Windows sed, from sed.sourceforge.net.
It is painfully slow. Ridiculously slow.
I'd like to try using Javascript to do some sed-style editing on text that comes through the browser.
Let's say I open up the Javascript console in a browser, e.g., Chrome.
I know little of Javascript but I do know about window.location() and XMLHttpRequest().
Assuming I can get the text I want to edit into the browser window... what do I do next?
- stygiansonic 11y agoIf you have Chrome dev tools open, you can go to the console and define a variable that holds your text using an ES6 string template, like so: var text = `Hello World: Here is a multiline piece of text` I would then follow this guide on JavaScript regex: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/R... Here's a short example/sample, based on the text above: (You should be able to copy-paste this directly into the console as well, following the declaration of `text` above) // Logs the lines to console that match a certain regex. // This is a very poor approximation of grep. var re = /(Hello|text)/g text.split("\n").forEach(function(line) { if (line.match(re)) { console.log(line); } }); Using the JavaScript console of your browser is a great way to learn the language, prototype ideas and sometimes to debug into your webapp. (Sometimes it feels like hotswap when using the JVM :))