Re: Prepend + to search words
- From: rvtol+news@xxxxxxxxxxxx (Dr.Ruud)
- Date: Thu, 29 Mar 2007 21:13:06 +0200
"John W. Krahn" schreef:
Grant:
?:
?:
Hello, how can I prepend a "+" character to each of the words in a
string? For example, "big blue widgets" should be changed to "+big
+blue +widgets".
I'd probably use an s/// (substitution) on the string. Match a word,
replace it with the plus sign and the word. Have you tried that?
I just had a look at some docs matching "perl substitution variable"
since the words in the string could be anything, but perl docs have a
way of overwhelming me really quickly. Can you show me how?
$ perl -le'$_ = "big blue widgets"; print; s/(\w+)/+$1/g; print'
big blue widgets
+big +blue +widgets
Alternative without capturing:
$ perl -wle'
$_ = q{big blue widgets};
print;
s/\b(?=\w)/+/g;
'
(see perlretut and perlre)
--
Affijn, Ruud
"Gewoon is een tijger."
.
- References:
- Prepend + to search words
- From: Grant
- Re: Prepend + to search words
- From: Tom Phoenix
- Re: Prepend + to search words
- From: Grant
- Re: Prepend + to search words
- From: John W. Krahn
- Prepend + to search words
- Prev by Date: Re: Prepend + to search words
- Next by Date: Re: Prepend + to search words
- Previous by thread: Re: Prepend + to search words
- Next by thread: Re: Prepend + to search words
- Index(es):
Relevant Pages
|