Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Regex To Remove File Extension

by dreadpiratepeter (Priest)
on Dec 10, 2008 at 19:01 UTC ( #729479=note: print w/replies, xml ) Need Help??


in reply to Regex To Remove File Extension

that is because you told it to take everything after a dot using a "greedy" match. You want a "non-greedy", using the ? modifier. try: /\..*?$/, alternately you could use /\.[^.]+$/ to remove a dot followed by one or more non-dot characters at the end of the string


-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

Replies are listed 'Best First'.
Re^2: Regex To Remove File Extension
by kennethk (Abbot) on Dec 10, 2008 at 19:07 UTC
    /\..*?$/ won't work because it still matches off the first period - I thought of that one at first, too. The second expression(/\.[^.]+$/) works fine.
      You are of course correct. I should pay more attention when responding to posts. In my defense, I was hard at work on some code and was distracted.


      -pete
      "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
        In your defense, my boss wishes I was hard at work on some code and was distracted.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://729479]
help
Chatterbox?
[marto]: fortunately my bad jokes and puns don't fall into those categories :P
[Corion]: :-D
Corion discovers a new shiny toy to try out over the (longish) weekend. Since I've done some more with websockets, maybe I'll try writing a webserver that implements hot-reloading of HTML(+CSS, +Javascript) in the browser. Edit the local file and ...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-04-26 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?