asmith Posted December 3, 2007 Share Posted December 3, 2007 why i can't get this working ? i want to search , the sentese must be start with a number , then must have --- then must contain letters and numbers . but this code accepts -- instead of ---, and if i don't start with a number it accept that too , please help ! <? $a = ---fdfg if (preg_match("/^[0-9]*---*[0-9a-zA-Z]/",$a)) {echo "yes";} else {echo "no";} ?> Link to comment https://forums.phpfreaks.com/topic/79937-solved-whats-wrong-with-this/ Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2007 Share Posted December 3, 2007 your regular expression should be if (preg_match("/^[0-9]+---+[0-9a-zA-Z]+/",$a)) Link to comment https://forums.phpfreaks.com/topic/79937-solved-whats-wrong-with-this/#findComment-404892 Share on other sites More sharing options...
asmith Posted December 3, 2007 Author Share Posted December 3, 2007 yea, works !thanks ! anyway what does + do ? Link to comment https://forums.phpfreaks.com/topic/79937-solved-whats-wrong-with-this/#findComment-404908 Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2007 Share Posted December 3, 2007 "+" matches once or more times so there has to be a occurance, "*" matches 0 or more so it will even match when there is no occurances Link to comment https://forums.phpfreaks.com/topic/79937-solved-whats-wrong-with-this/#findComment-404909 Share on other sites More sharing options...
asmith Posted December 3, 2007 Author Share Posted December 3, 2007 thanks a lot ! Link to comment https://forums.phpfreaks.com/topic/79937-solved-whats-wrong-with-this/#findComment-404918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.