正規表現 任意の1文字にマッチするピリオド「.」
記事作成日: 2022-02-18
.(ピリオド)
行末文字 ( \n、\r、\u2028、\u2029 ) を除くあらゆる 1 文字とマッチします。
使用例
// 任意の1文字を取得する
console.log('apple'.match(/./)); // Array [ "a" ]
console.log('apple'.match(/./g)); // Array(5) [ "a", "p", "p", "l", "e" ]
// 任意の2文字
console.log('apple'.match(/../)); // Array [ "ap" ]
console.log('apple'.match(/../g)); // [ "ap", "pl" ]
let str = '\t\n@{山@ '
console.log(str.match(/./)) // Array [ "\t" ]
console.log(str.match(/./g)) // Array(7) [ "\t", "@", "{", "山", "@", " ", " " ]
aから始まりtで終わる3文字の文字列
var str = 'art at act'
console.log(str.match(/a.t/g)) // Array [ "art", "act" ]
マッチしない例
console.log('at'.match(/.../)) // null
atは3文字ではないのでマッチしません。