PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Dec 16, 2017 5:26 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Nov 11, 2013 5:59 am 
Offline
Forum Newbie

Joined: Mon Nov 11, 2013 5:55 am
Posts: 2
I've got this regular expression below which removes common whole words($commonWords) from a string($input) an I would like to tweak it so that

1. it ignores those words (more than one word) in double or single quotes (like exact search in google search tab)
2. it remove words starting with hyphen ('-') but not those inside double or single quotes (like negative search in google search tab)

return preg_replace('/\b('.implode('|',$commonWords).')\b/i','',$input);

thanks


Top
 Profile  
 
PostPosted: Mon Nov 11, 2013 10:39 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13459
Location: New York, NY, US
You could use a regexp to first separate the text inside and outside of quotes. Then parse those with different rules.

I think you might be better off parsing the string word by word (or character by character) and maintaining state.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Tue Nov 12, 2013 6:22 am 
Offline
Forum Newbie

Joined: Mon Nov 11, 2013 5:55 am
Posts: 2
Makes sense. Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group