Jump to content

regex fails with optional 'the' ([Tt][Hh][Ee] )


rubing

Recommended Posts

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}';

Link to comment
Share on other sites

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!  8)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.