0

I have extract to class names from the html file and each line contains the class name like

      </div><div id='css-11_uss_pss_sss-__i__' class='sss'> <div class="sss-top">
      </div><div id='css-42_aap-8' class='css'> <div class="sss-top">

I need to extract the 'uss_pss_sss' and 'aap-8' from different lines

I try this code it extracts the first condition.

            preg_match("/(?<=_).*?(?=-__i__)/", $buffer, $match);

How do i extract the second line?

B L Praveen
  • 1,812
  • 4
  • 35
  • 60
  • http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Rob W Jun 17 '13 at 17:18

1 Answers1

0

You can't for two reasons:

1) aap-8 can't be a result of your pattern since it's not followed by -__i__ as indicated in your lookahead assertion

2) the preg_match function give only the first match, you must use preg_match_all instead

You can solve these two problems with:

preg_match_all("/(?<=_).*?(?=-(?:__i__)?|')/", $buffer, $matches);
print_r($matches);
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
  • I really thank replying to my question so fast, can you provide me some pattern to get the second condition. I am not getting how to match the second condtion.. – B L Praveen Jun 17 '13 at 17:22