preg_replace() to remove words beginning with a pattern
Hi,
How can I use preg_replace to determine if a string contains a word beginning with a pattern, and if it does, remove it?
Basically I want to capture query strings from a search, but throw away search modifiers. For example, the search query string:
site:daniweb.com query
would just become
query
In this case, I want to remove all words in the string that begin with 'site:'.
TIA!
cscgal
The Queen of DaniWeb
19,432 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Hi Maybe,
Thanks, that worked. I was doing two things wrong. Firstly, I was missing the beginning and trailing slash. Secondly, I spent a half hour trying to get it to work on the wrong search string ;)
cscgal
The Queen of DaniWeb
19,432 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Yeah, I'm just REALLLLLY bad with regex. And I haven't done it in quite awhile. Do you always use the forward and trailing slashes? I can't seem to figure out what they are there for. I kept trying to use the ^ and $ to start and end.
cscgal
The Queen of DaniWeb
19,432 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Ooh thanks. So \S is the same as ^\s ?
cscgal
The Queen of DaniWeb
19,432 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080