regex question

A

a

Hi,
str = c:/dir0/dir1/file.txt
str =~ /c:\/(.*)/
The $1 will equal to dir0/dir1/file.txt
I only want to have dir0 in $1
How should I put my regex?

Thanks
 
T

Tad McClellan

a said:
str = c:/dir0/dir1/file.txt
str =~ /c:\/(.*)/


Scalar variables in Perl start with a dollar character.

Statements in Perl are separated with a semicolon.

That is not Perl code.

The $1 will equal to dir0/dir1/file.txt


Only if the pattern match *succeeds*.

If it fails, it will have whatever value it had from a previous
successful match.

You should check to see if the match succeeded before accessing
the dollar-digit variables.

I only want to have dir0 in $1
How should I put my regex?


if ( $str =~ m#c:/([^/]*)# ) {
# use $1 here
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top