0
<a href="link">[BIOL 107 Section 1] Concepts in Biology</a></td>
<a href="link">[CENG 230 Section 7] Introduction to C Programming</a>
<a href="link">[CENG 230 All Sections] Introduction to C Programming</a></td>

That above sample is my code.

I am trying to get the anchors which does not contain ALL. I tried almost everything, looked regex documents but I couldn't come up with something works.

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
Rıdvan Çetin
  • 183
  • 5
  • 16
  • What is the question here? Remove lines from _where_? If this is PHP, where is the code that does this? Some lines of HTML isn't really enough to go on here. –  Jan 18 '17 at 02:43
  • Then please show us what you tried. It is however not good practice ([or evil by some](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454)) to use regexp to parse HTML. – J. Chomel Jan 18 '17 at 07:32

2 Answers2

0

Try with this regex:

<a\s*[^>]*?>(?![^<]*?All).*?<\/a>

Demo

0

DON'T use regex to parse HTML, use DOMDocument:

$html = '
<a href="link1">[BIOL 107 Section 1] Concepts in Biology</a>
<a href="link2">[CENG 230 Section 7] Introduction to C Programming</a>
<a href="link3">[CENG 230 All Sections] Introduction to C Programming</a>
';
$dom = new DOMDocument;
$dom->loadHTML($html);
$tags = $dom->getElementsByTagName('a');
$links = array();
$value = array();
foreach($tags as $a){
    if (preg_match('/\ball\b/i', $a->nodeValue)) continue;
    $links[] = $a->getAttribute('href');
    $value[] = $a->nodeValue;
}
print_r($links);
print_r($value);

Output:

Array
(
    [0] => link1
    [1] => link2
)
Array
(
    [0] => [BIOL 107 Section 1] Concepts in Biology
    [1] => [CENG 230 Section 7] Introduction to C Programming
)
Toto
  • 89,455
  • 62
  • 89
  • 125