regex to remove ordinals

后端 未结 5 1191
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 14:36

I need to remove ordinals via regex, but my regex skills are quite lacking. The following locates the ordinals, but includes the digit just prior in the return value. I need

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 14:49

    If you want to remove as well the numbers followed by ordinals you could use this one:

    [0-9]+(?:st| st|nd| nd|rd| rd|th| th)
    

    So for a given text: "The 3rd person is missing but the 2 nd and the 1st is here" you'll have this output: "The person is missing but the and the is here"

提交回复
热议问题