my dog learned polymorphism*
The moose likes Java in General and the fly likes regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "regex "" Watch "regex "" New topic
Author

regex "

Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 149
string



regex that works, finds two finds in group 0, that is:
<a class = "foo sitemap">
and
<a class="sitemap">



and the one that does not do the same, although I think it should(added extra "):


regex is unescaped coz testing here, where it is that auto done: webpage

Thanks for help.


Searchable nature photo gallery: http://agrozoo.net/jsp/Galery.jsp?l2=en
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18988
    
  40

Miran Cvenkel wrote:
regex that works, finds two finds in group 0, that is:
<a class = "foo sitemap">
and
<a class="sitemap">





Hmmmm.... Hate to say this. You regex does work for those two statements, but it seems to be doing it by pure luck. I don't think it does what you think it does.

Here is a break down of the regex:

1. <a -------------> Matches "<a".

2. .*? --------------> Matches anything of any length, but do so reluctantly.

3. clas -------------> Matches "clas"

4. s{0,) ------------> Matches zero or more letter "s"

5. ={0,} -----------> Matches zero of more equal signs.

6. .*? --------------> Matches anything of any length, but do so reluctantly.

7. sitemap ---------> Matches sitemap

8. .*? --------------> Matches anything of any length, but do so reluctantly.

9. > ----------------> Matches ">"

There are a lot of other possibilities that will match here... including...

<alaska is a state that can be classified as cold. What is the bluesitemapper code here ----<<<<<<<<anchor>




Miran Cvenkel wrote:
and the one that does not do the same, although I think it should(added extra "):


regex is unescaped coz testing here, where it is that auto done: webpage



The first regex has an optional (or many) equal sign following an "s". This actually won't submatch, the equal sign of the data for some cases because you have spaces between the "s" and the equal sign. The reason it worked, is because the equal sign is optional. It is actually not matching the equal sign of the regex, but matching the "match anything" that is following it.

The second regex has a mandatory quote, which breaks the lucky match that I just described.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 149
ahh,somewhere in the process I lost/overlooked missing \s before {0,}, hence nothing went OK.

Thanks for response.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regex "