-4

I'm trying to use a regular expression to search for a pattern where the string will always be 5 lowercase letters, 2 numbers, and then a lower case p.

Example:

ingja44p
James_Inger
  • 83
  • 2
  • 10
  • 2
    * See also [Open source RegexBuddy alternatives](http://stackoverflow.com/questions/89718/is-there) and [Online regex testing](http://stackoverflow.com/questions/32282/regex-testing) for some helpful tools, or [RegExp.info](http://regular-expressions.info/) for a nicer tutorial. – mario Dec 02 '12 at 22:35
  • 1
    So what exactly is it that you want? Do you want to make sure a string has this pattern? Do you want to find this pattern inside a larger string? Do you want to extract something (like the 2 digits) from the string? [Here is a great tutorial] to get you up to speed on regular expressions. And [this family of functions](http://php.net/manual/en/ref.pcre.php) is what you use in PHP. – Martin Ender Dec 02 '12 at 22:36
  • Lots of ppl downvoting lately... :( – Prof Dec 02 '12 at 22:37
  • 2
    @Prof83 the downvoting is not a problem, since the question shows no own effort and is not at all clear. The problem is people downvoting without leaving comments. – Martin Ender Dec 02 '12 at 22:39
  • I guess that's what i mean... only see you comment – Prof Dec 02 '12 at 22:40
  • 1
    What have you tried? Show us what you tried that doesn't work. Best of all, show us the code that you're using the regex in. – Andy Lester Dec 02 '12 at 22:40
  • @Prof83 and I didn't even downvote ;) – Martin Ender Dec 02 '12 at 22:42

2 Answers2

2

There are many utilities on the internet that can help you author and test your own regular expressions. For this case, though, you might try something like this:

$subject = "String to test";
$pattern = "#[a-z]{5}\d{2}p#";

if (preg_match($pattern, $subject)) {
   echo "A match was found.";
}
rjz
  • 16,182
  • 3
  • 36
  • 35
1
preg_match('/[a-z]{5}[0-9]{2}p/');

The / start and end the pattern: "/PATTERN/"

The [a-z]{5} means any lowercase letters a-z for length of 5

The [0-9]{2} means any 2 digits

p means, a "p" :)

Prof
  • 2,898
  • 1
  • 21
  • 38