• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regex "

 
Miran Cvenkel
Ranch Hand
Posts: 202
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21493
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Miran Cvenkel
Ranch Hand
Posts: 202
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh,somewhere in the process I lost/overlooked missing \s before {0,}, hence nothing went OK.

Thanks for response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic