返回課程

如何尋找省略號「...」?

重要性:5

建立一個正規表示法來尋找省略號:3 個(或以上?)連續的點。

檢查

let regexp = /your regexp/g;
alert( "Hello!... How goes?.....".match(regexp) ); // ..., .....

解答

let regexp = /\.{3,}/g;
alert( "Hello!... How goes?.....".match(regexp) ); // ..., .....

請注意,點是一個特殊字元,因此我們必須跳脫它並插入為 \.