#author("2020-06-18T04:38:55+09:00","default:ryuichi","ryuichi")
* キャプチャーしない括弧 (?:) [#y1987121]

 var match = "XABX".match(/(A|B|C)/);
 console.log(match);
 console.log(match[1]);
 
   [ 'A', 'A', index: 1, input: 'XABX', groups: undefined ]
   A

- 普通に括弧(A|B|C)を使うと、キャプチャーされてmatch[1]にマッチしたAが入る

 var match = "XAX".match(/(?:A|B|C)/);
 console.log(match);
 console.log(match[1]);
 
 
   [ 'A', index: 1, input: 'XAX', groups: undefined ]
   undefined

- 括弧(?:A|B|C)を使うと、キャプチャーされずmatch[1]はundefinedになる



トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS