Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > regexp assistance

Reply
Thread Tools

regexp assistance

 
 
mike
Guest
Posts: n/a
 
      10-12-2009
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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-12-2009
mike <(E-Mail Removed)> wrote:
> /^.*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
 
Reply With Quote
 
 
 
 
mike
Guest
Posts: n/a
 
      10-12-2009
On 12 Okt, 15:36, Jürgen Exner <(E-Mail Removed)> wrote:
> mike <(E-Mail Removed)> wrote:
> > /^.*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?


http://www.somacon.com/p127.php

> See 'perldoc perlre' and probably 'perldoc perlretut'.
>
> jue


 
Reply With Quote
 
mike
Guest
Posts: n/a
 
      10-12-2009
On 12 Okt, 15:57, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> Jürgen Exner wrote:
> > mike <(E-Mail Removed)> wrote:
> >> /^.*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?

>
> It's in table 5.7 (Alphanumeric Regex Metasymbols) of the camel book!
>
> BugBear


My question is still not answered...

//mike
 
Reply With Quote
 
sreservoir
Guest
Posts: n/a
 
      10-12-2009
mike wrote:
> 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.

--

"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe"
 
Reply With Quote
 
Marc Girod
Guest
Posts: n/a
 
      10-12-2009
On Oct 12, 2:25*pm, mike <(E-Mail Removed)> wrote:

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


Parentheses?

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

Marc
 
Reply With Quote
 
Ramon F Herrera
Guest
Posts: n/a
 
      10-12-2009
On Oct 12, 10:45*am, Marc Girod <(E-Mail Removed)> wrote:
> On Oct 12, 2:25*pm, mike <(E-Mail Removed)> wrote:
>
> > * * * * /^.*Inds|Reset|Response\.java\z/s

>
> 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

 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      10-12-2009
On Mon, 12 Oct 2009 06:25:38 -0700 (PDT), mike <(E-Mail Removed)> wrote:

>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



 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      10-12-2009
On Mon, 12 Oct 2009 08:31:35 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

>On Mon, 12 Oct 2009 06:25:38 -0700 (PDT), mike <(E-Mail Removed)> wrote:
>
>>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

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

 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      10-12-2009
On Mon, 12 Oct 2009 16:17:31 +0100, Ben Morrow <(E-Mail Removed)> wrote:

>
>Quoth Sherm Pendley <(E-Mail Removed)>:
>> mike <(E-Mail Removed)> writes:
>>
>> > Is \z not to match at the end of a string?

>>
>> Yes, but $ is far more commonly used for that.

>
>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
RegExp Assistance VUNETdotUS Javascript 3 10-18-2007 09:29 PM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp assistance? kelvlam Javascript 4 09-14-2006 07:33 PM
My regexp stupidity needs assistance before loose all my hair! trans. (T. Onoma) Ruby 21 01-18-2005 08:51 PM



Advertisments