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