From: Aaron Fude on
Hi,

I try the following and it produces no matches:

Pattern pattern = Pattern.compile("ab*s");
Matcher matcher = pattern.matcher("abacus");

while (matcher.find()) {
System.out.println(matcher.start() + " " + matcher.end());
}


I must not understand regular expressions at all. What am I missing?

Thanks!
From: Eric Sosman on
On 6/20/2010 5:03 PM, Aaron Fude wrote:
>
> I try the following and it produces no matches:
>
> Pattern pattern = Pattern.compile("ab*s");
> Matcher matcher = pattern.matcher("abacus");
>
> while (matcher.find()) {
> System.out.println(matcher.start() + " " + matcher.end());
> }
>
> I must not understand regular expressions at all. What am I missing?

What Stefan Ram said, to which I might add that you probably
want "ab.*s" as your pattern.

--
Eric Sosman
esosman(a)ieee-dot-org.invalid
From: Joshua Cranmer on
On 06/20/2010 05:03 PM, Aaron Fude wrote:
> Hi,
>
> I try the following and it produces no matches:
>
> Pattern pattern = Pattern.compile("ab*s");
> Matcher matcher = pattern.matcher("abacus");
>
> while (matcher.find()) {
> System.out.println(matcher.start() + " " + matcher.end());
> }
>
>
> I must not understand regular expressions at all. What am I missing?

What you are probably attempting is a form often known as "globbing" as
opposed to the standard regex or Perl-compatible regex.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
From: Roedy Green on
On Sun, 20 Jun 2010 14:03:54 -0700 (PDT), Aaron Fude
<aaronfude(a)gmail.com> wrote, quoted or indirectly quoted someone who
said :

>I try the following and it produces no matches:

You did not specify the patterns you want. For background see
http://mindprod.com/jgloss/regex.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

There is no harm in being sometimes wrong especially if one is promptly found out.
~ John Maynard Keynes (born: 1883-06-05 died: 1946-04-21 at age: 62)
From: Daniel Pitts on
On 6/20/2010 2:03 PM, Aaron Fude wrote:
> Hi,
>
> I try the following and it produces no matches:
>
> Pattern pattern = Pattern.compile("ab*s");
> Matcher matcher = pattern.matcher("abacus");
>
> while (matcher.find()) {
> System.out.println(matcher.start() + " " + matcher.end());
> }
>
>
> I must not understand regular expressions at all. What am I missing?
>
> Thanks!
In regex, "*" indicates 0 or more repetitions of the previous atom. In
other words, your patter will match one 'a', followed by any number of
'b', followed by an 's'

abacus does not match that description.

You can use the '.' character, which matches any. so "ab.*s" (as
someone else has pointed out), WILL match abacus.



--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>