Javascript Regex Match Capture is returning whole match, not group

前端 未结 3 1355
心在旅途
心在旅途 2020-12-18 20:24
re = /\\s{1,}(male)\\.$/gi

\"A girl is a female, and a boy is a male.\".match(re);

this results in \" male.\"

what i want is \"male\"

3条回答
  •  不知归路
    2020-12-18 20:55

    You need to take out the 'g' option on your regexp:

    re = /\s{1,}(male)\.$/i
    

    yields

    [" male.", "male"]
    

提交回复
热议问题