1
在JavaScript中/(\n.)/g
捕獲一個換行符和它後面的第一個字符。 我需要它的反面。這不過是換行符和跟隨它的第一個字符。我想嘗試/(?!\n.)/g
但它不起作用。否定這個正則表達式/(n.)/g
如
const regex = /\n./g;
const str = `All the world's a stage,
And all the men and women merely players;
They have their exits and their entrances,`;
const subst = ` `;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
這將返回:
換人結果:整個世界是一個舞臺,第二所有的男人和 演員而已;哎有自己的出口及其出入口,
但是我想:
換人結果:AT
代替一切,除了換行和它後面
的第一個字符
任何例如字符串和預期的結果?你想刪除文本或提取它?也許你只是想使用's.split(/ \ n ./)'? –
使用否定字符類別(set):'/ [^ \ n] ./ g' – falsetru
不幸的是,JavaScript正則表達式不支持lookbehind,但是@ falsetru的註釋應該可以工作 – alex