> I'm using Java 1.4.2_05 and need some help getting a logical OR to work
> within my pattern matcher.
[quoted text clipped - 7 lines]
> colon followed by 2 numerals followed by a comma followed by anything
> followed by a one or 0 delete character OR the end of the line/string.
So how is the end of the String special in this regard? What is
difference between the case where there is no \u007f and when you want
to match end-of-input?
The two specific strings you provided are both matched by this pattern:
"[0-9]{2}/[0-9]{2}:[0-9]{2},.+\\u007f?"
(without necessity of any regex options). Are there other strings that
need to be matched by the pattern but aren't?
> Here is the regex:
> Pattern.compile("[0-9]{2}[\u002F][0-9]{2}[\u003A][0-9]{2}[\u002C].+[\u007F?]|[$]",
[quoted text clipped - 6 lines]
> ... [\u007f]?|[$]
> These don't work either.
When you put the $ in a character class, it represents a literal '$'
character, not end-of-input / end-of-line. It is unlikely in your case
that you need to explicitly look for end-of-line at all.
You may find this regex testing tool useful:
http://www.fileformat.info/tool/regex.htm

Signature
John Bollinger
jobollin@indiana.edu
Shawna - 27 May 2005 05:16 GMT
Thanks John. An alarm is coming in from some switch equipment via a
modem. My stuff reads the characters from on a socket. Usually the
alarms are terminated with a delete character, but not always. So I'm
looking for some sort of end of string as well as the delete. However,
in the cases without a delete, I may have to just have to rely on a
time-out.
Shawna
John C. Bollinger - 27 May 2005 15:59 GMT
> Thanks John. An alarm is coming in from some switch equipment via a
> modem. My stuff reads the characters from on a socket. Usually the
> alarms are terminated with a delete character, but not always. So I'm
> looking for some sort of end of string as well as the delete. However,
> in the cases without a delete, I may have to just have to rely on a
> time-out.
By the time you match the String against the pattern you must have
already parsed it from the input, so the question of matching a message
boundary is at a lower level. Are you saying, though, that when there
is a delete character in the input, you can tolerate other, unspecified
data afterward? You could write that into the pattern, but it might be
more appropriate to look into the differences in behavior between
Matcher.matches(), Matcher.lookingAt(), and Matcher.find(). One of the
latter two may serve your purpose better than the first.
Also, I didn't previously say so, but you probably want to construct an
explict Pattern object and use Matchers based on it, rather than using
String.matches(). Not only does doing so give you more flexibility, but
if you hold on to the Pattern object and reuse it then you also save the
work of parsing the pattern string for every match attempt.

Signature
John Bollinger
jobollin@indiana.edu