regexp assistance

M

mike

Hi,

I am trying to get files that looks like:

xxxInds.java
yyyReset.java
zzzRespone.java

I am using the following regexp:

return unless -f $File::Find::name;
/^.*Inds|Reset|Response\.java\z/s

I get files with another file extension than java.

Is \z not to match at the end of a string?

br,

//mike
 
J

Jürgen Exner

mike said:
/^.*Inds|Reset|Response\.java\z/s

'z' isn't special in a RE, therefore the backslash is redundant.
I get files with another file extension than java.

Is \z not to match at the end of a string?

No, what gave you that idea?
See 'perldoc perlre' and probably 'perldoc perlretut'.

jue
 
S

sreservoir

mike said:
Hi,

I am trying to get files that looks like:

xxxInds.java
yyyReset.java
zzzRespone.java

I am using the following regexp:

return unless -f $File::Find::name;
/^.*Inds|Reset|Response\.java\z/s

this gets:
anything with Inds in it
anything with Reset in it
anything that ends with Response.java
I get files with another file extension than java.

Is \z not to match at the end of a string?

Yes, though you might get "Response.java\n", iirc.

Which probably still doesn't aswer your implicit question, but you
didn't ask.
 
R

Ramon F Herrera

Parentheses?

/^.*(Inds|Reset|Response)\.java\z/s

Marc


Parentheses will be the bane of me. I always seem to have too few or
too many. The crux of such problem is that parentheses have two
distinct purposes in regexes:

(1) The normal grouping used in math and programming languages.

(2) The "grab this part" function.

Who invented regexes anyway, was it Larry Wall? I would have used
angle brackets for the functionality (2) above.

-Ramon
 
S

sln

Hi,

I am trying to get files that looks like:

xxxInds.java
yyyReset.java
zzzRespone.java

I am using the following regexp:

return unless -f $File::Find::name;
/^.*Inds|Reset|Response\.java\z/s

/^.*(?:Inds|Reset|Response)\.java$/s
-sln
 
S

sln

The difference is important. /$/ will match before a newline at the end
of the string; /\z/ will not. When you are certain your strings won't
contain newlines, there is no difference, but once you start considering
using /m and /s you should also consider whether you need /\z/ instead
of /$/.

Ben

I guess \A\Z\z in multiple lines, mean "only" to be once.

-sln
 
J

Jürgen Exner

bugbear said:
It's in table 5.7 (Alphanumeric Regex Metasymbols) of the camel book!

I stand corrected. It is listed in perlre in the zero-width assertions
category.

jue
 
R

Randal L. Schwartz

Peter> Please open 'perldoc perlre' and search for \z.

"I keep searching for \z, but all I find is the end of string!"

:)
 
S

Steve C

Randal said:
Peter> Please open 'perldoc perlre' and search for \z.

"I keep searching for \z, but all I find is the end of string!"

:)


My problem is that I've been searching for $ for years and never
find enough.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top