正则表达式删除字符串中最后一个逗号后的所有内容

TTa*_*Ta4 0 regex perl

我想在Perl中编写一个正则表达式,它将删除字符串中最后一个逗号之后的所有内容.我知道最后一个逗号之后的子字符串是一个数字或其他一些子字符串,所以没有逗号.

示例:some\string,/doesnt-really.metter,5.

我想正则表达式删除最后一个逗号,5所以输出将是:some\string,/doesnt-really.metter

我不允许仅使用正则表达式使用任何其他模块.那么我应该使用哪个正则表达式?

另一个例子:

string_with,,,,,_no_point,some_string => string_with,,,,,_no_point

Dav*_*ell 5

如果逗号后跟一个或多个数字,则可以使用:s/,\d+$//.更一般地说,使用s/,[^,]*$//(匹配逗号后跟零个或多个非逗号字符,后跟字符串结尾).