What is the purpose of the passive (non-capturing) group in a Javascript regex?

后端 未结 5 1834
渐次进展
渐次进展 2021-01-12 11:05

What is the purpose of the passive group in a Javascript regex?

The passive group is prefaced by a question mark colon: (?:group)

In other words

5条回答
  •  天命终不由人
    2021-01-12 11:47

    When you want to apply modifiers to the group.

    /hello (?:world)?/
    /hello (?:world)*/
    /hello (?:world)+/
    /hello (?:world){3,6}/
    

    etc.

提交回复
热议问题