-1

I'm trying to match only the /blog?page=1 (only with page=1) and I have written the regex for it that is /blog\?page=1

but it is also matching with /blog?page=11. Is this possible only to match it with /blog\?page=1 ?

kamal pal
  • 4,187
  • 5
  • 25
  • 40
Ali Nouman
  • 3,304
  • 9
  • 32
  • 53
  • why use regex if you only want to match /blog?page=1, you can easily achive this with [strpos()](http://php.net/manual/en/function.strpos.php) – Wolfeh May 31 '16 at 09:01
  • 1
    why you are trying to math with regex, isn't this information available in `$_GET['page']` ? – kamal pal May 31 '16 at 09:03
  • 1
    I suggest that you do the basic exercises at [regexone.com](http://regexone.com). You will get the grasp of regex basics and will be able to handle such issues by yourself. Pay special attention to [Lesson 10](http://regexone.com/lesson/line_beginning_end) and [Lesson 15](http://regexone.com/lesson/misc_meta_characters). – Wiktor Stribiżew May 31 '16 at 09:04
  • 1
    @kamalpal Thanks for the tip. – Ali Nouman May 31 '16 at 09:10
  • 1
    @WiktorStribiżew Thanks I will check that out. Many thanks! – Ali Nouman May 31 '16 at 09:11

2 Answers2

1

You need to use anchors: \/blog\?page=1$ . This will assert the position at end of the string.

Now, depending on what your are trying to match, if you are looking for the first digit only, for example, you can use this: \/blog\?page=\d . You can also use a capture group, to retrieve just the number: \/blog\?page=(\d).

Lucas Araujo
  • 1,648
  • 16
  • 25
1

You need to add end of string character which is $

nospor
  • 4,190
  • 1
  • 16
  • 25