How do I make part of a regular expression optional in Ruby?

后端 未结 4 947
无人及你
无人及你 2020-12-06 01:32

To match the following:

On Mar 3, 2011 11:05 AM, \"mr person\" 
wrote: 

I have the following regular expression:

/(On.* (?         


        
4条回答
  •  清歌不尽
    2020-12-06 01:57

    Sure, you just need to group the optional part...

       (at )*
    

    And, ok, I guess that will match at at at at, so you might want to just do:

       (at )?
    

提交回复
热议问题