-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
  • 305,248
  • 71
  • 524
  • 547
Pavel Kenarov
  • 844
  • 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,079
  • 5
  • 40
  • 59