-1

How can i parse all names from html with regular expression. So, I tried so much, but couldnt.

I want only collect name, surnames and code from this html.

Like this; Edward Michael 1000, John Kramer 2000, David Duncan 3000 ..etc

<div class="rightside">
     <div style="display: block">
        <div class="frame preBack">
            <div class="framelist">
                <ul>
                    <li uid ="1" code="1000" class="framerow frm0">
                        <div class="frm name" >
                            Edward
                        </div>
                        <div class="frm surname">
                            Michael
                        </div>
                    </li>
                    <li uid ="2" code="2000" class="framerow frm1">
                        <div class="frm name" >
                            John
                        </div>
                        <div class="frm surname">
                            Kramer
                        </div>
                    </li>
                </ul>
            </div>
        </div>
        <div class="frame preBack">
            <div class="framelist">
                <ul>
                    <li uid ="3" code="3000" class="framerow frm3">
                        <div class="frm name" >
                            David
                        </div>
                        <div class="frm surname">
                            Duncan
                        </div>
                    </li>
                    <li uid ="4" code="4000" class="framerow frm4">
                        <div class="frm name" >
                            Alice
                        </div>
                        <div class="frm surname">
                            Pole
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>

Gracias.

Anirudha
  • 32,393
  • 7
  • 68
  • 89
  • why would you want to do this with regex? More to the point its not possible, to target just names. What regex system are you using? If you're using JS why would you not just concat the text? – Jamie Hutber Jul 12 '13 at 06:53
  • In general, [this](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). In particular, regular expression dialects vary wildly; you should tag with the flavour (javascript, perl, java, ruby...). But I definitely suggest you rather use a HTML library, not a RE one. – Amadan Jul 12 '13 at 06:54
  • what languate/tool are you using – Anirudha Jul 12 '13 at 06:59
  • I use Php. Are there any library or framework to parse with Php? – Shawn Oberg Jul 12 '13 at 07:02
  • which version of php are using or any framework ? – Tushar Gupta - curioustushar Jul 12 '13 at 07:14
  • None of them. Now, only I try to parse this html. – Shawn Oberg Jul 12 '13 at 07:18
  • I find this with simplehtmldom. But, not yet. $html = str_get_html($str); foreach($html->find('ul') as $ul) { foreach($ul->find('li') as $li){ echo $li->innertext . '
    '; } }
    – Shawn Oberg Jul 12 '13 at 07:35
  • simplehtmldom.sourceforge.net, How can I make with this library? – Shawn Oberg Jul 12 '13 at 07:58

1 Answers1

0

Here is the required output : using Jquery

http://jsfiddle.net/afsar_zan/VaDVE/1/

console.log($.each('.frm name','.frm surname').text());
Afsar
  • 3,104
  • 2
  • 25
  • 35