JavaScript正则表达式 - 从单词旁边提取数字 [英] JavaScript Regular Expression - Extract number from next to word
本文介绍了JavaScript正则表达式 - 从单词旁边提取数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
自从我触及正则表达式以来已经很久了。这很简单,但我把头发拉过来。
Been a long time since I have touched regular expressions. It's simple but I am pulling my hair out over it.
我有一个字符串,我从DOM MIN20,MAX40
获得。我希望能够在JavaScript中使用正则表达式来提取 MIN
旁边的整数以及 MAX
旁边的整数,并且放入单独的变量 min
和 max
。我无法想办法。
I have a string as follows that I get from the DOM "MIN20, MAX40"
. I want to be able to use regex in JavaScript to extract the integer next to MIN
and the integer next to MAX
and put into separate variables min
and max
. I cannot figure a way to do it.
感谢谁曾帮助过我,你将成为一名救生员!
Thanks to who ever helps me, you will be a life saver!
干杯
推荐答案
您可以使用:
var input = "MIN20, MAX40";
var matches = input.match(/MIN(\d+),\s*MAX(\d+)/);
var min = matches[1];
var max = matches[2];
这篇关于JavaScript正则表达式 - 从单词旁边提取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文