0

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)

the result has to return the whole thing(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:

show_clipping.php?CLIP_id=5
  1. How do I match numeric part properly?
  2. Another issue is that the value 575 can contain any numeric value, my regex will not work after 3 digits, how do i make it work with infinit amount of digits
4

5 回答 5

2

您没有指定您使用的语言,所以这里只是regex

'([^']+)'

解释

'       # Match a single quote
([^`])+ # Capture anything not a single quote
'       # Match the closing single quote 

所以基本上它用单引号捕获所有内容,show_clipping.php?CLIP_id=5位于第一个捕获组中。

在这里看到它的动作

只捕获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
于 2012-12-01T11:10:07.130 回答
1

答案:^(0|[1-9][0-9]*)$ 之前回答: 数值的正则表达式模式

(答案6)

于 2012-12-01T11:15:30.557 回答
1

那这个呢?

onclick.match(/show_clipping\.php\?CLIP_id=\d+/)
["show_clipping.php?CLIP_id=575"]

(从你的问题的标签我假设你正在使用 JavaScript)

于 2012-12-01T11:32:27.010 回答
0
show_clipping.php\?CLIP_id=(\d+)

\d匹配一个数字,+表示其中一个或多个。

于 2012-12-01T11:12:00.380 回答
0

怎么样:

/(show_clipping.php\?CLIP_id=[1-9]\d*)/
于 2012-12-01T11:13:03.433 回答