POV-Ray : Newsgroups : povray.off-topic : RegEx help Server Time
4 Sep 2024 07:18:31 EDT (-0400)
  RegEx help (Message 1 to 7 of 7)  
From: Chambers
Subject: RegEx help
Date: 9 May 2010 13:40:00
Message: <web.4be6f30c8bf12a8ce79f0df40@news.povray.org>
Hey all, I know it's been a while since I've posted here, but I also know there
are some regex wizards who read these groups...

I never bothered learning regular expressions, but we're going over them for one
of my classes, and I'm having trouble searching for strings at the end of a line
with $.

As I understand it, $ matches for the end of the line.  Fine.  When I search
just for $, I get every line (as I should).

However, when I try to append $ onto any other expression, I don't get a single
match - not one - when I know there should be some.  For instance, the
following:
ing[.]$

Should search for any line ending in "ing."  Searching just for "ing[.]" returns
the hits I want (plus a few more), but "ing[.]$" doesn't return a single hit.

Any tips as to what I'm doing wrong?


Post a reply to this message

From: Darren New
Subject: Re: RegEx help
Date: 9 May 2010 14:43:30
Message: <4be70252$1@news.povray.org>
Chambers wrote:
> Any tips as to what I'm doing wrong?

Firstly, which regexp engine are you using? They're all slightly different.

Second, if you want to search for a literal period, probably \. is better 
than [.].

Depending on your engine, you might need to escape the $ also.

In other words, the problem is not so much with your regular expression as 
it is with expression the right regular expression to the RE interpreter 
you're using. What you're searching for ought to work, so the problem is 
either (1) you have spaces between the period and end of line, or (2) you 
are not passing the string to the RE engine that ends with "end of line" 
match marker.

Try searching for
   ing[. ]+$
and see if you get matches with one or more spaces between the ing. and the EOL.

-- 
Darren New, San Diego CA, USA (PST)
    Ada - the programming language trying to avoid
    you literally shooting yourself in the foot.


Post a reply to this message

From: bart
Subject: Re: RegEx help
Date: 9 May 2010 15:12:02
Message: <4be70902$1@news.povray.org>
Chambers wrote:
> Hey all, I know it's been a while since I've posted here, but I also know there
> are some regex wizards who read these groups...
> 
> I never bothered learning regular expressions, but we're going over them for one
> of my classes, and I'm having trouble searching for strings at the end of a line
> with $.
> 
> As I understand it, $ matches for the end of the line.  Fine.  When I search
> just for $, I get every line (as I should).
> 
> However, when I try to append $ onto any other expression, I don't get a single
> match - not one - when I know there should be some.  For instance, the
> following:
> ing[.]$
> 
> Should search for any line ending in "ing."  Searching just for "ing[.]" returns
> the hits I want (plus a few more), but "ing[.]$" doesn't return a single hit.
> 
> Any tips as to what I'm doing wrong?
>  
Pattern "ing[.]$" matches exactly as you expected,
when applied to the text with Unix-style line endings (\n),
but for Win-style line endings (\r\n) it
doesn't match your input.


Post a reply to this message

From: Chambers
Subject: Re: RegEx help
Date: 9 May 2010 23:45:00
Message: <web.4be780c014fb0cf2e79f0df40@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Chambers wrote:
> > Any tips as to what I'm doing wrong?
>
> Firstly, which regexp engine are you using? They're all slightly different.

I'm using grep, but I don't know what version.  It's a virtual linux machine
that I access via a web browser for labs for class... I could do a local
install, but it wouldn't have the files we're supposed to work with.

> Second, if you want to search for a literal period, probably \. is better
> than [.].

That's what I would have thought, but I found that \. didn't return any matches,
whereas [.] did.  Probably a quirk of the version I was using.

> In other words, the problem is not so much with your regular expression as
> it is with expression the right regular expression to the RE interpreter
> you're using. What you're searching for ought to work, so the problem is
> either (1) you have spaces between the period and end of line, or (2) you
> are not passing the string to the RE engine that ends with "end of line"
> match marker.

Thanks, I turned in my lab report with what I thought should work, and noting
that it didn't.  That was the only problem with it, so I doubt I'll lose too
many points.

....Chambers


Post a reply to this message

From: Darren New
Subject: Re: RegEx help
Date: 10 May 2010 01:06:27
Message: <4be79453@news.povray.org>
Chambers wrote:
> That's what I would have thought, but I found that \. didn't return any matches,
> whereas [.] did.  Probably a quirk of the version I was using.

Probably because you're using the shell, so it's eating the first \

Try \\. where you need a ., since the shell will take away one \ and grep 
will take away the other.

> Thanks, I turned in my lab report with what I thought should work, and noting
> that it didn't.  That was the only problem with it, so I doubt I'll lose too
> many points.

Good luck. Let us know what the answer is? :-)

You know, I bet if you're invoking it from the command line, the shell might 
be swallowing the $ also.  That's one of the things I hate about this sort 
of thing - quoting hell.

-- 
Darren New, San Diego CA, USA (PST)
    Ada - the programming language trying to avoid
    you literally shooting yourself in the foot.


Post a reply to this message

From: Warp
Subject: Re: RegEx help
Date: 10 May 2010 07:07:53
Message: <4be7e909@news.povray.org>
Chambers <bdc### [at] yahoocom> wrote:
> That's what I would have thought, but I found that \. didn't return any matches,
> whereas [.] did.  Probably a quirk of the version I was using.

  How are you running grep? And from where?

  If you give a regexp to grep as a command-line parameter, remember to
always escape the entire regexp so that the shell won't mess it up. In
other words:

   grep 'ing\.'

not:

   grep ing\.

which will end up completely different when grep sees it.

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: RegEx help
Date: 10 May 2010 07:08:51
Message: <4be7e943@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Try \\. where you need a ., since the shell will take away one \ and grep 
> will take away the other.

  A lot easier and more intuitive to simply use quotes:

    grep 'ing\.'

  It probably explains the $ not working as well (because the shell might
be eating it).

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.