0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptで文字列が正規表現に合致するかどうかを判別する

Posted at

Solution: RegExp.prototype​.test()を使おう

  1. 正規表現を定義する
  2. チェックしたい文字列を定義した正規表現のtest()メソッドでチェックする
  3. Booleanで値が返ってくる
const validRegexFormat = RegExp('hoge*')
const string1 = 'hoge'
const string2 = 'bar'
console.log(validRegexFormat.test(string1)) // => true
console.log(validRegexFormat.test(string2)) // => false
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?