Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: appending to end of string

by KPeter0314 (Deacon)
on Jun 25, 2003 at 22:06 UTC ( [id://269036]=note: print w/replies, xml ) Need Help??


in reply to appending to end of string

What you probably want is something like s/copyright.*$/$&, 2005/g. I would really try to narrow the search string down some more though.

Since you have "copyright*" as the match string, you are matching copyright or copyrightttt or copyrightttttt, but not "copyright 2003-2004" so the operator you are doing just leaves the rest of the string alone and only works with the part that matches. That is why you get the doubling up of 2003-2004.

If you want to match "copyright 2003-2004" or basically copyright-to-the-end-of-the-line, then use "copyright.*$" to get it all. If not, then build a match that includes the numbers too. The dot-star bit is bad and should be eliminated. You should look at your data and build a better match. See Death to Dot Star! for more.

Some of my details on the exact matching might be a little off, I'm still just a learner on regex's too.

-Kurt

Update: ++demerphq for an even better explanation.

Replies are listed 'Best First'.
Re: Re: appending to end of string
by demerphq (Chancellor) on Jun 25, 2003 at 22:16 UTC

    The dot-star bit is bad and should be eliminated.

    Bah. Thats cargo-cult if you ask me. Now if you said "dot-star on ocassion may not behave as you want it to so you should be careful using it" then I wouldn't say this. :-)

    The point is that you dont have to freak out just because you see a .* around. (I wonder how many there are in the standard modules? Hmmm) Do be careful, do read Death to Dot Star! (and advise other to do so as well,) do consider alternative before using it, but dont feel that you have to eliminate .* every time you see it.


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://269036]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found