Convert srt to text using javascript

var a = `15:22W
15:24X`; //INPUT SRT TEXT

var result = a.split(/\r?\n/).map (a=>a.substring(a.indexOf(a.match(/[a-zA-Z]/) ))).join(' ')

copy(result) // uses the chrome dev tools console copy command. Note that for this to work, run this script as a chrome snippet in source tab of chrome dev tools

//window.prompt("Copy to clipboard: Ctrl+C, Enter", result); // NOTE: this works only for small srt files as the clipboard size is limited
OUTPUT: "W X"

 

FOR NODE.JS, USE:

const clipboardy = require('clipboardy');
let a = clipboardy.readSync();
var result = a.split(/\r?\n/).map (a=>a.substring(a.indexOf(a.match(/[a-zA-Z]/) ))).join(' ')
//const util = require('util');
//require('child_process').spawn('clip').stdin.end(util.inspect(result));
clipboardy.writeSync(result);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s