regex to remove ordinals

后端 未结 5 1200
爱一瞬间的悲伤
爱一瞬间的悲伤 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:57

    In perl:

    $var =~ s{\b(\d+)(?:st|nd|rd|th)\b}{$1};
    

    In PHP:

    $var = preg_replace('/\\b(\d+)(?:st|nd|rd|th)\\b/', '$1', $var);
    

    In .NET:

    var = Regex.Replace(@"\b(\d+)(?:st|nd|rd|th)\b", "$1");
    

提交回复
热议问题