Skip to content

removing a word, the following space and the next word

4 messages · Bob Green, Andrew Robinson, jim holtman +1 more

#
I am hoping for advice as to how I could remove all words immediately 
following the words 'Mr' or 'Mr.' in  a csv file. For example, the 
following phrases are included in lines of text (along with other Mr) 
that could be anywhere in the file: "Mr Jones ate lunch" and "Mr 
Smith was tied".


I want to remove the words Jones and Smith (etc) leaving the other 
text intact.

Any suggestions are appreciated,

regards


Bob
#
Hi Bob,

I recommend doing some background reading on regular expressions[1]
and using gsub().

Cheers

Andrew

[1] http://en.wikipedia.org/wiki/Regular_expressions
On Sat, Sep 20, 2008 at 04:24:36PM +1000, Bob Green wrote:

  
    
1 day later
#
On 21/09/2008, at 5:15 AM, jim holtman wrote:

            
I don't get what the bit

	<file://0.0.0.1/>

is about.  If I do (just)

	gsub('(Mr\\.*)\\s+\\w+', "\\1 xxxx", x)

I get the desired result, i.e.


[1] "Mr xxxx ate lunch and Mr xxxx was tied"

	cheers,

		Rolf Turner


	

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}