[英]regular expression match numeric value
I'm trying to match a pattern: 我正在尝试匹配一个模式:
show_clipping.php?CLIP_id=*
from: 从:
a href="javascript:void(0);" onclick="MM_openBrWindow('show_clipping.php?CLIP_id=575','news','scrollbars=yes,resizable=yes,width=500,height=400,left=100,top=60')">some text</a>
where 哪里
*
can be only numeric values(eg: 0, 1 , 1234) 只能是数字值(例如:0、1、1234)
the result has to return the whole thing( show_clipping.php?CLIP_id=575
) 结果必须返回整个内容(
show_clipping.php?CLIP_id=575
)
what I've tried: 我尝试过的
show_clipping.php\?CLIP_id=([1-9]|[1-9][0-9]|[1-9][0-9][0-9])
but my attempt would truncate the rest of the digits from 575, leaving the results like: 但我的尝试是截断575中的其余数字,结果如下:
show_clipping.php?CLIP_id=5
You didn't specify what language your are using so here is just the regex
: 您没有指定要使用的语言,因此这里只是
regex
:
'([^']+)'
Explanation 说明
' # Match a single quote
([^`])+ # Capture anything not a single quote
' # Match the closing single quote
So basically it capture everything in single quotes, show_clipping.php?CLIP_id=5
is in the first capture group. 因此,基本上,它使用单引号捕获所有内容,
show_clipping.php?CLIP_id=5
在第一个捕获组中。
See it action here. 在这里看到它的动作。
To only capture show_clipping.php?CLIP_id=5
I would do '(.*CLIP_id=[0-9]+)'
只捕获
show_clipping.php?CLIP_id=5
我会做'(.*CLIP_id=[0-9]+)'
' # Match a single quote
(.* # Start capture group, match anyting
CLIP_id= # Match the literal string
[0-9]+) # Match one of more digit and close capture group
' # Match the closing single quote
Answer: ^(0|[1-9][0-9]*)$ answered before: Regex pattern for numeric values 答案:^(0 | [1-9] [0-9] *)$之前回答: 数字的正则表达式
(answer number 6) (第6个答案)
What about this? 那这个呢?
onclick.match(/show_clipping\.php\?CLIP_id=\d+/)
["show_clipping.php?CLIP_id=575"]
(From the tags of your question I assume you're using JavaScript) (根据您问题的标签,我认为您正在使用JavaScript)
show_clipping.php\?CLIP_id=(\d+)
\\d
匹配一个数字, +
表示其中1个或多个。
怎么样:
/(show_clipping.php\?CLIP_id=[1-9]\d*)/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.