Match a string against multiple patterns

前端 未结 2 983
甜味超标
甜味超标 2020-12-01 02:14

How can I match a string against multiple patterns using regular expression in ruby.

I am trying to see if a string is included in an array of prefixes, This is not

2条回答
  •  悲哀的现实
    2020-12-01 02:19

    If you can use a single string, it might be faster to write a regex containing the possible values.

    e.g.

    /(Mr\.|Mrs\.| ... )/.match(name)
    

提交回复
热议问题