0
alt="Abdul Aziz" width="75" height="75" class="thumb-border"></td>

I want to select "Abdul Aziz" from the html above. How should I do this? It must be generic as I have to select many names from similar looking HTML.

Leigh
  • 28,765
  • 10
  • 55
  • 103
Usman Tahir
  • 2,513
  • 4
  • 24
  • 38
  • What platform? What language? Do you realize that regex tends to be a [poor choice for parsing HTML](http://stackoverflow.com/a/1732454/1583)? – Oded Dec 31 '12 at 21:23
  • It's not always wise to use regex on HTML. There are nice parsing libraries for almost all platform, might give that a try. – SWeko Dec 31 '12 at 21:24
  • Could you please mention the whole tag ? if you are using jQuery or YUI you could use selector. – Mehdi Karamosly Dec 31 '12 at 21:24
  • Client-side Javascript is _especially_ well equipped to getting an attribute of an existing element. If you have jQuery, you can do it just as easily _and_ with a shorter syntax than with vanilla.js – John Dvorak Dec 31 '12 at 21:26
  • Well actually it was an assignment of my subject Java Development I was forced to do this with RE using java by Professor – Usman Tahir Dec 31 '12 at 21:29

3 Answers3

1

Not sure what language you are using, but here's a pattern that would start to get you there. Beware that parsing HTML with regexes has all sorts of downsides.

"/alt=\"(.*?)\".*?>/"

This will retrieve the stuff between alt="" into the first capture group.

DWright
  • 9,258
  • 4
  • 36
  • 53
1
alt="[\w\s]+"

Will select the whole statement, and then you can remove the alt and quotes with your code.

Will Richardson
  • 7,780
  • 7
  • 42
  • 56
0

Using Javascript would be more consistent:

//You can get elements by tag :
els = document.getElementsByTag('td');

// or you can get elements by class name :
els = document.getElementsByClassName('thumb-border');

and then iterate through your elements and read the alt attribute.

or if using jQuery you can use selector:

http://api.jquery.com/category/selectors/

Mehdi Karamosly
  • 5,388
  • 2
  • 32
  • 50