0

How can I find a 3 character text pattern in a string of: an upper or lowercase alphabetic character (a to z or A to Z) followed by a numeric character (0 to 9) followed by an upper or lowercase alphabetic character (a to z or A to Z)

for example x4A or A3j or A7X or h1k

1
  • I looked and those pattern matches did not fit my requirement. I also know I could loop through testing but that is pretty inefficient Commented Jun 16, 2012 at 11:42

4 Answers 4

2

I think you should use

/[a-zA-Z][0-9][a-zA-Z]/
Sign up to request clarification or add additional context in comments.

Comments

1
$matches = array();
preg_match('/[a-z]\d[a-z]/i', $my_string, $matches);
// now $matches contains all you want

1 Comment

1

try :

[a-zA-Z]{1}[0-9][a-zA-Z]{1}

demo : http://regexr.com?3199m

1 Comment

I tested this and iax87e5 returned true when it should be false
0

Try this:

preg_match_all('/[A-Za-z]{1}[0-9]{1}[A-Za-z]{1}/',$string,$matches);

$matches now contains all your matches.

1 Comment

I tested this and iax87e5 returned true when it should be false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.