使用正则表达式从字符串中提取数字 [英] Extracting numbers from a string using regular expressions
本文介绍了使用正则表达式从字符串中提取数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对正则表达式一无所知,但我知道它们是我在这里尝试执行的操作的正确工具:我正在尝试从这样的字符串中提取数值:
I am clueless about regular expressions, but I know that they're the right tool for what I'm trying to do here: I'm trying to extract a numerical value from a string like this one:
approval=not requested^assignment_group=12345678901234567890123456789012^category=Test^contact_type=phone^
理想情况下,我会从中提取以下内容:12345678901234567890123456789012
我尝试过的所有正则表达式都不起作用.我怎样才能从这个字符串中得到我想要的值?
Ideally, I'd extract the following from it: 12345678901234567890123456789012
None of the regexes I've tried have worked. How can I get the value I want from this string?
推荐答案
mystr.match(/assignment_group=([^\^]+)/)[1]; //=> "12345678901234567890123456789012"
这将找到从assignment_group="结尾到下一个脱字符^
符号的所有内容.
This will find everything from the end of "assignment_group=" up to the next caret ^
symbol.
这篇关于使用正则表达式从字符串中提取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文