Catfish Posted January 23, 2010 Share Posted January 23, 2010 If I had the string: Your Chief of Intelligence dispatches 1 spies to attempt to sabotage 16 of Remco-MOD's weapons of type Lookout Tower. Your spies successfully enter Remco-MOD's armory undetected and I wanted the name of the weapon and knew it could be a variable number of words for the weapon I would use: <?php $string = "Your Chief of Intelligence dispatches 1 spies to attempt to sabotage 16 of Remco-MOD's weapons of type Lookout Tower. Your spies successfully enter Remco-MOD's armory undetected"; preg_match('/.*weapons of type ([\w|\s]*)\. Your spies.*/', $string, $matches); print_r($matches); ?> Tested this code and it was working. Even worked with "Board with a Nail in it" as the weapon. PS: Explaining the regexp: it is looking for any number (*) of words (\w) or (|) whitespace characters (\s) between the strings on either side of the words and whitespaces. Also note that I had to escape the fullstop (\.) immediately after the weapon, since . is a reserved character in regexps. Quote Link to comment https://forums.phpfreaks.com/topic/188837-regex-query-stripping-away-unwated-text/page/2/#findComment-1000556 Share on other sites More sharing options...
iLuke Posted January 24, 2010 Author Share Posted January 24, 2010 Well then thank you very very much for your help! I've learned a lot doing this stuff... it's a pain in the neck if I'm honest, but it sure is useful! The tutorials on the net just aren't really up to standard... it's more of a copy/paste operation from what I've seen. Anyways, thanks again! Luke. Quote Link to comment https://forums.phpfreaks.com/topic/188837-regex-query-stripping-away-unwated-text/page/2/#findComment-1000909 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.