Is it possible to use a Regex to match all lines that have 2 words that are not the same ?
I do understand that I can use \d+: ([,\w]+ )\1|(.+)/gm
This is where you capture the lines with the same word
Then capture everything else
Then you run the function to only do something with group 2
But is there a way to only match the lines that are not the same
1: 43,186 43,186
2: 296,531 296,531
3: 108086 108086
4: abcdef abcdef
5: Capture This
6: 497,802 497,802
7: 200,062 300,062
8: Not Same
9: 202232 252232
10: 4,324,452 4,324,452
Example:
let string = `
1: 43,186 43,186
2: 296,531 296,531
3: 108086 108086
4: abcdef abcdef
5: Capture This
6: 497,802 497,802
7: 200,062 300,062
8: Not Same
9: 202232 252232
10: 4,324,452 4,324,452 `;
let magicalRegex = /\d+: (This One) (Does not match this one)/gm;
string.replace(magicalRegex, matched=>{
/*These are the matches I found master*/
`
5: Capture This
7: 200,062 300,062
8: Not Same
9: 202232 252232
`
/*Run some special code*/
/*Return matched*/
});
First Second Third
isNum: Anything Must Match Second