-3

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

3
  • I have tried with something like '/(-i _[0-9])/' but without success Commented Jun 26, 2013 at 8:31
  • 1
    Why would that work? There's no underscore in there... /-i\d+/ Commented Jun 26, 2013 at 8:33
  • Neither is there any quantifier in the pattern Commented Jun 26, 2013 at 8:34

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

So much of an effort for a new user :P
@Jari Question was not well-formed but it was new user's mistake. ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.