Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
javascriptで「暗い」または「明るい」に一致する正規表現をどのように記述しますか. 置き換えられるのは完全な単語です。
これを試して:
str.match(/\b(dark|light)\b/g)
デモ: http://jsfiddle.net/zhggQ/
/\b(?:dark|light)\b/g
単語全体のみに一致します。見て
replace
これを試して
"ダークまたはライト".replace(/(ダーク|ライト)/g,"その他")
/(\sdark\s|\slight\s)/ 単語の前後に任意の先頭または末尾のスペースに対応する必要があります