是否可以向后子串。我的意思是我有一个像这样的字符串:
Test_Test_T_630
or
TestTest_Test_T_6305
or
TestTestTest_Test_T_63050
是否可以相应地 trim 它:
Test_Test_T
or
TestTest_Test_T
or
TestTestTest_Test_T
我知道你不能使用子字符串来查找 _T,因为这会 trim 得太早,所以你可以向后查找最后一个下划线吗?
最佳答案
yourstring.slice(0, yourstring.lastIndexOf('_T')+2)
您也可以使用正则表达式。
关于JavaScript 子字符串向后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9600339/