[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: A Regular Expression Question



On Tue, 10 Jun 2014 14:01:20 -0500
"Martin G. McCormick" <martin@server1.shellworld.net> wrote:

> I am trying to remove the & or ampersand sign from some perl
> code I wrote as it is not necessary. I have no trouble finding
> all the instances because they consist of an ampersand
> immediately followed by a letter so &[a-z] describes the case
> perfectly. 
> The replacement pattern should actually be the same as the
> search pattern except that it is missing the & or ampersand.
> 
> 	The scripts have loads of logical &'s and &&'s in them
> so the regular expression seems to be the safest way to globally
> replace &everything with just everything. In this case, a global
> pattern that returned the search pattern missing it's first
> letter would even work.


$ sed -r 's/&//' test.txt >test.txt.filtered
$ cat test.txt.filtered 

I am trying to remove the  or ampersand sign from some perl
code I wrote as it is not necessary. I have no trouble finding
all the instances because they consist of an ampersand
immediately followed by a letter so [a-z] describes the case
perfectly. 
The replacement pattern should actually be the same as the
search pattern except that it is missing the  or ampersand.

	The scripts have loads of logical 's and &&'s in them
so the regular expression seems to be the safest way to globally
replace everything with just everything. In this case, a global
pattern that returned the search pattern missing it's first
letter would even work.


Then:
$ sed -r 's/&&//' test.txt.filtered > test.txt.filtered.2
$ cat test.txt.filtered.2 

I am trying to remove the  or ampersand sign from some perl
code I wrote as it is not necessary. I have no trouble finding
all the instances because they consist of an ampersand
immediately followed by a letter so [a-z] describes the case
perfectly. 
The replacement pattern should actually be the same as the
search pattern except that it is missing the  or ampersand.

	The scripts have loads of logical 's and 's in them
so the regular expression seems to be the safest way to globally
replace everything with just everything. In this case, a global
pattern that returned the search pattern missing it's first
letter would even work.

-- 
Mel : Does guy's brain unscrambler exist? :'(
Blondin : yep
Blondin : it is called beer

Attachment: signature.asc
Description: PGP signature


Reply to: