5

[JavaScript] Append Text at the Beginning of Each Line

 3 years ago
source link: http://siongui.github.io/2018/01/11/javascript-append-text-at-the-beginning-of-each-line/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

[JavaScript] Append Text at the Beginning of Each Line

January 11, 2018



Paste your lines below:


Lines after prepended:

The first textarea is the lines to be prepended. The second textarea is the lines after prepended. The JavaScript code to append text at the beginning of each line is:

afterTextareaElm.value = oriTextareaElm.value.replace(/^/gm, inputElm.value);
  • ^ means beginning of line.
  • g means global match
  • m means multiline matching

If you are not familiar with JavaScript regular expression, see [3].


References:

[1]Search Links of Major Search Engines

[2][sed] Append Text at the Beginning of Each Line

[4]css - HTML Textarea isn't responsive - Stack Overflow


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK