Pattern Match - Don't Understand this particular one 
Author Message
 Pattern Match - Don't Understand this particular one

Hi,

I have this pattern match that grabs the file name out of a path name...for
instance if you have a string that says:

C:\windows\desktop\thing.jpg

This pattern should grab just "thing.jpg" and it does but I don't understand
FULLY why and am asking for a little help if anyone doesn't mind.

/([^\/\\]+)$/

So the ( ) just reserves the stuff in there into variable $1 for later...

But in English this says what?  Take the end of the string ($) up to (+) a
part where it begins with a  / or a \ (^).
Am I translating that correctly?  Anyone like to clear this up?

Thanks!

-Matt



Wed, 18 Jun 1902 08:00:00 GMT  
 Pattern Match - Don't Understand this particular one

Quote:

>Hi,

>I have this pattern match that grabs the file name out of a path name...for
>instance if you have a string that says:

>C:\windows\desktop\thing.jpg

>This pattern should grab just "thing.jpg" and it does but I don't understand
>FULLY why and am asking for a little help if anyone doesn't mind.

>/([^\/\\]+)$/

>So the ( ) just reserves the stuff in there into variable $1 for later...

yes, in this case...

Quote:
>But in English this says what?  Take the end of the string ($) up to (+) a
>part where it begins with a  / or a \ (^).
>Am I translating that correctly?  Anyone like to clear this up?

it says:

match the longest possible substring of one or more non-forward-slash,
non-backslash characters that occurs just before the end of the string in
question, and put it (the substring) into $1
--
| Michael Budash Consulting     | 707-252-7670 voice |
| Perl, Javascript, PHP, MySQL  | 603-250-8679 fax   |



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. (newbie) Don't understand '$_'

2. strange regex behaviour - don't understand what's going on

3. combine two pattern matches to one match?

4. match where 2 characters in a row don't match

5. I don't understand these results.

6. @list = <wildcard>, I don't understand how this works

7. sothing I don't understand - undef

8. Don't understand how to use open2 package

9. Bug or I don't understand Perl

10. I don't understand!

11. Don't understand the statement: 1;

12. don't understand use strict;

 

 
Powered by phpBB® Forum Software