Compare more than two documents

96 views Asked by At

EDIT: Mea culpa! Committed the cardinal sin of asking for a library recommendation and was swiftly put to rights. Here's the problem: I have two or more pieces of text. For example:

a: Here's some text.

b: Here's some more text.

c: Here's some text with the word blue.

And want to get:

'Here's some <var_1>text<var_2>.'

where

var_1 document a holds ''

var_1 document b holds 'more '

var_1 document c holds ''

var_2 document c holds ''

var_2 document b holds ''

var_2 document c holds ' with the word blue'

This is for a Javascript-based web app heavily reliant on jQuery; however for testing I need solution that is compatible with node.js.

1

There are 1 answers

2
Kaiido On

A simple regex like /(.*)text(.*)/ might do it.

Then you can use String.match() method to get the values of the capturing groups.

var str = ["Here's some text","Here's some more text.","Here's some text with the word blue."];

for (var i = 0; i<str.length; i++){
    var res = str[i].match(/(.*)text(.*)/);
    log("document "+i+" var_1 : "+res[1]+"<br>"+"document "+i+" var_2 : "+ res[2]+"<br>");
  }

function log(msg){
    document.querySelector('p').innerHTML+= msg;
  }
<p/>