取决于你想如何匹配它(从开始的 x 距离或从结束的 x 距离)
/(.).{2}$/
倒数第三个(捕获第 1 组)
/^.{21}(.)/
第 22 个字符(捕获第 1 组)
//PHP
$str = '73746174652C313A312C310D';
$char = preg_replace('/(.).{2}$/','$1',$str); //3rd from last
preg_match('/(.).{2}$/',$str,$chars); //3rd from last
$char = $chars[1];
preg_match('/^.{21}(.)/',$str,$chars); //22nd character
$char = $chars[1];
//JS
var str = '73746174652C313A312C310D';
var ch = str.replace(/(.).{2}$/,'$1'); //3rd from last
var ch = str.match(/(.).{2}$/)[1]; //3rd from last
var ch = str.match(/^.{21}(.)/)[1]; //22nd character
如果您必须使用First match:
工具位的结果,请运行两次:
73746174652C313A312C310D
- ^.{21}.
= 73746174652C313A312C31
73746174652C313A312C31
- .$
= 1