programguru Posted June 11, 2008 Share Posted June 11, 2008 I am and really stumped, and I wanted to know if anyone could shed some light on my misunderstanding. Using the * in a match - of course * means zero or more of the previous char If sama*ntha matches: sammntha, samantha, and samaaantha why would it not match smantha ?? Can anyone explain this? I cannot find a sensible answer online and it driving me nuts! Link to comment https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/ Share on other sites More sharing options...
TravisJRyan Posted June 11, 2008 Share Posted June 11, 2008 because its doing this match literally "sam" match "a" optionally and as many times match literally "ntha" http://www.regular-expressions.info/ And check out regex buddy. Handy tool Link to comment https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/#findComment-562835 Share on other sites More sharing options...
programguru Posted June 11, 2008 Author Share Posted June 11, 2008 So it appears to be matching everything literal after and before "a" but obviously "a" does not need to exist, so "smantha" would evaluate to false. So the correct explanation of * would be "looking for exact strings prior and after the previous char marked with *" Like: john*na johnona would return true johnnnna would return true jonnna would return false Am I getting this or dreaming? Link to comment https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/#findComment-562848 Share on other sites More sharing options...
Orio Posted June 11, 2008 Share Posted June 11, 2008 That's right. ab*c would match: ac abc abbc abbbc abbbbc etc' Orio. Link to comment https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/#findComment-562938 Share on other sites More sharing options...
lordfrikk Posted June 11, 2008 Share Posted June 11, 2008 So the correct explanation of * would be "looking for exact strings prior and after the previous char marked with *" Quantifier applies only to what is immediately in front of it, which could be either character, (non-)capturing parentheses, character class. Link to comment https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/#findComment-563052 Share on other sites More sharing options...
programguru Posted June 12, 2008 Author Share Posted June 12, 2008 lordfrikk, That makes sense, but I am not sure why would "sama*ntha" evaluate true for "sammntha"? As you can see "sama" is no part of it. TravisJRyan seemed to clarify this, but am I missing something? Link to comment https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/#findComment-563623 Share on other sites More sharing options...
TravisJRyan Posted June 12, 2008 Share Posted June 12, 2008 lordfrikk, That makes sense, but I am not sure why would "sama*ntha" evaluate true for "sammntha"? As you can see "sama" is no part of it. TravisJRyan seemed to clarify this, but am I missing something? I tried expr "sama*ntha" on this test case "sammntha" no matches Link to comment https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/#findComment-563633 Share on other sites More sharing options...
programguru Posted June 12, 2008 Author Share Posted June 12, 2008 TravisJRyan! I think I misunderstood you. I missed a char in my test ??? But I understand what you mean now. Thanks! Link to comment https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/#findComment-563646 Share on other sites More sharing options...
TravisJRyan Posted June 13, 2008 Share Posted June 13, 2008 TravisJRyan! I think I misunderstood you. I missed a char in my test ??? But I understand what you mean now. Thanks! Cool. . glad to help Link to comment https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/#findComment-564412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.