Regex 获取子字符串正则表达式

Regex 获取子字符串正则表达式,regex,Regex,如何从字符串C27_W112_V113_Table_6_1字符串6或字符串C27_W120_V153_Table_22_1字符串22获取。thx您可以通过两种方式实现它 正则表达式方法: 常数re=/\d+\d+$/; 设值=[ ‘C27_W112_V113_表6_1’, ‘C27_W120_V153_表_uuu22_uu1’ ]; values.forEachstr=>console.logstr.matchre[1]; 字符串操作我假设值始终位于同一位置: values.forEachstr

如何从字符串C27_W112_V113_Table_6_1字符串6或字符串C27_W120_V153_Table_22_1字符串22获取。thx

您可以通过两种方式实现它

正则表达式方法: 常数re=/\d+\d+$/; 设值=[ ‘C27_W112_V113_表6_1’, ‘C27_W120_V153_表_uuu22_uu1’ ]; values.forEachstr=>console.logstr.matchre[1]; 字符串操作我假设值始终位于同一位置: values.forEachstr=>{ 让反转=str.split.reverse.join; 设index=reversed.indexOf''; console.logreversed.sliceindex+2,reversed.indexOf''u u u2;',index+1; }; 这里有一个片段

常数re=/\d+\d+$/; 设值=[ ‘C27_W112_V113_表6_1’, ‘C27_W120_V153_表_uuu22_uu1’ ]; values.forEachstr=>console.logstr.matchre[1]; console.log'---'; values.forEachstr=>{ 让反转=str.split.reverse.join; 设index=reversed.indexOf''; console.logreversed.sliceindex+2,reversed.indexOf''u u u2;',index+1;
};你试过什么?另外,字符串是否总是以_1结尾?不,最后一个数字可以是1-99。