Community Patterns

Community Library Entry

0

Regular Expression
Created·2017-02-28 17:29
Flavor·PCRE (Legacy)

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

Description

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 = '<html><head><title>Foo</title></head><body><table' . $matches[1] . 'table></body></html>'; // Fix the few errors in the HTML $doc = new DOMDocument (); $doc->loadHTML($procHTML);

Submitted by Christopher Cilley