CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Adding text between words

 



Rivotti
User

Mar 27, 2000, 5:29 AM

Post #1 of 3 (1009 views)
Adding text between words Can't Post

Image I have this text:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>See if you can read this<HR></BLOCKQUOTE>

Is it possible to add the text "## You can't ##" between each word using regular expressions? The final text should be:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>S## You can't ##e## You can't ##e## You can't ## ## You can't ##i## You can't ##f## You can't ## ## You can't ##y## You can't ##o## You can't ##u## You can't ## ## You can't ##c## You can't ##a## You can't ##n## You can't ## ## You can't ##r## You can't ##e## You can't ##a## You can't ##d## You can't ## ## You can't ##t## You can't ##h## You can't ##i## You can't ##s## You can't ##<HR></BLOCKQUOTE>


japhy
Enthusiast

Mar 27, 2000, 7:38 AM

Post #2 of 3 (1009 views)
Re: Adding text between words [In reply to] Can't Post

Sure, you can do that with a regular expression. But do you want it between WORDS or CHARACTERS? Your question asks about words, but your final result implies characters. I'll show you the method for characters:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$string = "abc";
$string =~ s/(?<=.)(?=.)/ABC/gs;
print $string;
# aABCbABCc
</pre><HR></BLOCKQUOTE>


Rivotti
User

Mar 27, 2000, 8:15 AM

Post #3 of 3 (1009 views)
Re: Adding text between words [In reply to] Can't Post

Japhy:

Thank you. You were right. I want characters not words. Just one more thing: could you explain the syntax? I get a little confused with regular expressions.

Another thing I posted a question in "Getting code from a section in a html page". Could you see it?

Once again thank you
Rivotti

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives