Regex/code for removing “FWD”, “RE”, etc, from email subject

后端 未结 3 1606
时光说笑
时光说笑 2021-02-07 14:35

Given an email subject line, I\'d like to clean it up, getting rid of the \"Re:\", \"Fwd\", and other junk. So, for example, \"[Fwd] Re: Jack and Jill\'s Wedding\" should turn i

3条回答
  •  自闭症患者
    2021-02-07 15:13

    The following regex will match all of the cases in the way that I would expect it to do so. I'm not sure if you will agree, because not every case has been explicitly documented. It is almost certainly possible to simplify this, but it is functional:

    /^((\[(re|fw(d)?)\s*\]|[\[]?(re|fw(d)?))\s*[\:\;]\s*([\]]\s?)*|\(fw(d)?\)\s*)*([^\[\]]*)[\]]*/i
    

    The final result in the match will be the stripped subject.

提交回复
热议问题