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

Re: help on reg ex

by svsingh (Priest)
on May 07, 2003 at 15:39 UTC ( [id://256253]=note: print w/replies, xml ) Need Help??


in reply to help on reg ex

I'm not really clear on what you're asking for with extracting /great and putting it back. Both the inital and resulting $a's in your question look the same to me.

Here's what I came up with...

my $a = '/export/home/test/great'; $a =~ / (.*) (\/[^\/]*) /x; my $front = $1; my $back = $2; print "a: $a\n"; print "front: $front\n"; print "back: $back\n";

Note: I'm using /x to add some whitespace to the regex for clarity. You can ignore the spaces.

That returns...

a: /export/home/test/great front: /export/home/test back: /great

I think the other solutions are affected by regex greed. So they'll pull out the longest string starting with a slash. If I'm oversimplifying things, then I'm sorry.

I hope this helps.

Replies are listed 'Best First'.
Re: Re: help on reg ex
by Anonymous Monk on May 20, 2003 at 15:55 UTC
    I must have forgotten to thank you , thanks for helping me out

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://256253]
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-03-29 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found