-3

what regular expression i must use if i want to extract "-i123213131345" from URL like this http://example.com/blabla-bla-i123213131345/blabla

Gordon
  • 312,688
  • 75
  • 539
  • 559
Pavel Kenarov
  • 944
  • 1
  • 9
  • 21

1 Answers1

0

Try -i[0-9]+ pattern.

Sample:

$str = 'http://example.com/blabla-bla-i123213131345/blabla';
$pattern = '/-i[0-9]+/';
preg_match($pattern, $str, $matches);
var_dump($matches);

Demo

Here's useful tool to play with regexes before you implement them. Also it helps a lot to learn Regex.

Leri
  • 12,367
  • 7
  • 43
  • 60