mrhenniger Posted March 16, 2010 Share Posted March 16, 2010 I am new to regular expressions but I hope to build some competance on the subject. For now though I am just a newbie. I am trying to create a regex were the haystack is expected to be small (only 10 characters or less), and a match is to be confirmed when the subject string fits the full length of the haystack. Here is the regex I have created in PHP... $number = preg_match("/^(N[CGLRSX]{0,1}[0-9]{1-3}[A-Z]{0,2})$/", $aCR); When I provide the values "N1Z" for $aCR, I expect to get a value of 1 for $number, but instead I get 0. Hmmmm.... What it looks straight forward, but obviously I am doing something wrong. Can anyone point out the error of my ways? Thanks in advance for any assistance you can provide. Mike Link to comment https://forums.phpfreaks.com/topic/195423-matching-an-exact-length-linestring/ Share on other sites More sharing options...
cags Posted March 16, 2010 Share Posted March 16, 2010 Your concept is actually right, but I think you made a typo. {1-3} should obviously be {1,3}. I believe {1-3} would match itself as a literal string so your $aCR would have to be something like "N1{1-3}Z" in order to match the pattern. Link to comment https://forums.phpfreaks.com/topic/195423-matching-an-exact-length-linestring/#findComment-1026919 Share on other sites More sharing options...
mrhenniger Posted March 17, 2010 Author Share Posted March 17, 2010 That was it! If it wasn't for all of my typos I would be a genius. Thanks. Mike Link to comment https://forums.phpfreaks.com/topic/195423-matching-an-exact-length-linestring/#findComment-1027376 Share on other sites More sharing options...
cags Posted March 17, 2010 Share Posted March 17, 2010 Wouldn't we all Link to comment https://forums.phpfreaks.com/topic/195423-matching-an-exact-length-linestring/#findComment-1027380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.