0
有一個BRAINFREEZE簡單正則表達式替換所有但
我有以下字符串:「pvtVal ROW1 COL3這是一個測試」
如何擺脫任何不pvtVal行\ d +或山坳\ d +
因此,例如:
var test="pvtVal row1 col3 this is a test".replace(/(^(pvtVal |row\d+ |col\d+))/g, '');
遺憾的是它不工作。
感謝
有一個BRAINFREEZE簡單正則表達式替換所有但
我有以下字符串:「pvtVal ROW1 COL3這是一個測試」
如何擺脫任何不pvtVal行\ d +或山坳\ d +
因此,例如:
var test="pvtVal row1 col3 this is a test".replace(/(^(pvtVal |row\d+ |col\d+))/g, '');
遺憾的是它不工作。
感謝
而不是替換,你可以做到這一點使用String.match()
和Array.join()
var teststr = 'pvtVal row1 col3 this is a test',
matches = teststr.match(/(?:pvtVal|row\d+|col\d+)/g),
results = matches.join(' ');
console.log(results); // => "pvtVal row1 col3"
Jah比我的好。今天陷入一種思維模式,一切看起來都像釘在我的錘子上。 :) +1 – zx81
您可以使用'match'和'而是join'。 – zneak