Regular Expressions 101

Community Library

Your search did not match anything

Community Library Entry

0

Regular ExpressionOpen Workspace

/
^(?:(?:(?!table).)*table){19}(.+?(?=table))
/
gsi

Description
Created·2017-02-28 17:29
Type·Match
Flavor·PCRE (Legacy)

3rd party generated HTML (Purchase Order) was rife with errors, so direct import was impossible. Decided to pull the particular table out of the HTML attachment, and then wrap that as "new" HTML for import into DOMDocument.

PHP code: preg_match('/^(?:(?:(?!table).)*table){19}(.+?(?=table))/is', $rawHTML, $matches); $procHTML = 'Foo<table' . $matches[1] . 'table>'; // Fix the few errors in the HTML $doc = new DOMDocument (); $doc->loadHTML($procHTML);

Submitted by Christopher Cilley
Open Workspace