JavaScript regex在字符串后获取数字 [英] JavaScript regex get number after string
本文介绍了JavaScript regex在字符串后获取数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在令人震惊地意识到JavaScript中的正则表达式与PCE中的正则表达式有些不同之后,我坚持以下内容。
After coming to the shocking realization that regular expressions in JavaScript are somewhat different from the ones in PCE, I am stuck with the following.
在php 我提取了一个数字 x:
(?x)[0-9]+
在JavaScript中,由于捕获括号差异导致无效组,因此相同的正则表达式不起作用。
In JavaScript the same regex doesn't work, due to invalid group resulting from the capturing parenthesis difference.
所以我正在尝试为了实现同样的微不足道的功能,但我一直得到 x和数字:
So I am trying to achieve the same trivial functionality, but I keep getting both the x and the number:
(?:x)([0-9]+)
如何在不包含x的情况下捕获> x之后的数字?
How do I capture the number after x without including x?
推荐答案
这也有效:
/(?:x)([0-9] +)/。 test('YOUR_STRING');
然后,值你想要的是:
RegExp。$ 1 //组1
这篇关于JavaScript regex在字符串后获取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文