rubing Posted March 30, 2008 Share Posted March 30, 2008 howdy pardners, i got some trouble here... I am trying to match input from an email message of the form; 'show place' and then extract the value of place. So, I wrote this little snippet of code, which does the job well! $pat='[sS][Hh][Oo][Ww] [[:alnum:]._\'\"&]{1,150}'; ereg($pat, $email, $query_word); $message_body =$query_word[0]; $nopat=' [[:alnum:]._\'\"&]{1,150}'; ereg($nopat, $message_body, $query_final); $message_final =$query_final[0]; However, now I realize that users will sometimes enter: 'show the place' (e.g. show the rockies), in which case my regex miserably fails I tried to rewriting my pattern as follows, but now it won't match anything. :-\ $pat='[sS][Hh][Oo][Ww] [([Tt][Hh][Ee] )[:alnum:]._\'\"&]{1,150}'; Quote Link to comment Share on other sites More sharing options...
rubing Posted March 30, 2008 Author Share Posted March 30, 2008 allrighty i figured out that $pat='[sS][Hh][Oo][Ww] (([Tt][Hh][Ee] )[[:alnum:]._\'\"&]{1,150}|[[:alnum:]._\'\"&]{1,150})'; will pick up either 'show place' or 'show the place' now i just got to figure out how to exctract just the place for either case! Quote Link to comment Share on other sites More sharing options...
effigy Posted March 31, 2008 Share Posted March 31, 2008 Use PREG and its case insensitive modifier: /show\s+(?:the\s+)?([\w.\"\"&]{1,150})/i Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.