Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 765 Bytes

string.md

File metadata and controls

34 lines (23 loc) · 765 Bytes

String

Replace line breaks with

let str = str.replace(/\n|\r\n|\r/g, '<br>');

Remove extension from filename

https://stackoverflow.com/questions/1818310/regular-expression-to-remove-a-files-extension

var input = 'myfile.png';
var output = input.substr(0, input.lastIndexOf('.')) || input;

Get extension from filename

https://stackoverflow.com/questions/190852/how-can-i-get-file-extensions-with-javascript

return filename.split('.').pop();

Replace bracket tags

https://stackoverflow.com/questions/43931283/javascript-string-replace-short-tags-with-brackets

var string = '<div id="test">A little [prefix] test</div>';
var replace = string.replace(/\[prefix\]/g, "replaced");
console.log(replace);