Re: Trouble with regular expressions



On Jul 29, 10:48 am, markspace <nos...@xxxxxxxxxxx> wrote:
laredotornado wrote:

The assertion ("m1.matches") fails, even though "pageString.indexOf"
returns a value greater than -1, indicating the string is found.  So
I'm missing something fundamental about regular expressions.

m1.matches() means "the regex matches the WHOLE STRING", not some
portion of it.

Use m1.region(int start, int end) to restrict the matches() method to
one part of your input string.

Or use find() (or lookingAt()) to match substrings (indexOf() uses
find(), I believe).

Indeed, when I changed to "find" instead of "matches", everything
worked out great. 5 stars. - Dave
.



Relevant Pages

  • Re: Trouble with regular expressions
    ... I'm missing something fundamental about regular expressions. ... portion of it. ... to restrict the matchesmethod to one part of your input string. ...
    (comp.lang.java.programmer)
  • Re: Question: Optional Regular Expression Grouping
    ... The core problem is that the regex matches ... that ambiguity; it merely attempts to make the module prefer the match ... the pattern rather than in the string literal. ...
    (comp.lang.python)
  • Re: Regular expressions question
    ... Yes: I said that the regex matches an empty string: So here you match ... A regex can contains whitespaces!! ...
    (microsoft.public.dotnet.languages.vc)
  • Re: pattern match
    ... with the /x modifier it matches and assigns the string you ... Remember that greediness never affects whether a regex matches or not. ... Gunnar Hjalmarsson ...
    (comp.lang.perl.misc)
  • Re: java String split returns an additional first empty string
    ... > array of Strings. ... I always get the first String in the array as an ... So you will get an empty string if the regex matches the 1st part of the ...
    (comp.lang.java.programmer)