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

5 Answers 5

2

You didn't specify what language your are using so here is just the 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.

See it action here.

To only capture show_clipping.php?CLIP_id=5 I would do '(.*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
Sign up to request clarification or add additional context in comments.

1 Comment

can i limit the result to the first group only?
1

Answer: ^(0|[1-9][0-9]*)$ answered before: Regex pattern for numeric values

(answer number 6)

Comments

1

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)

Comments

0
show_clipping.php\?CLIP_id=(\d+)

\d matches a digit, and + means 1 or more of them.

Comments

0

How about:

/(show_clipping.php\?CLIP_id=[1-9]\d*)/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.