php - How to put two regexs together -


I've been stumped I'm getting two regexs that are making me individually important, but I'm not sure That's how they work in combination.

\ b ([a-zA-Z])? \ D {5} \ b After finding the correct 5 letters, the wire is finding an alternative single letter pattern.

& lt; A \ s + (?: [^ & Gt;] *? \ S +)? Href = "([^" * *] " is matching the URL to an anchor tag.

Now that I want to match (for replacement purposes)) 5 digits (Without or without the preceding letter) that is within the URL of an anchor tag.

Sample content:

This lesson should be 3 matches, 3 inclusive The numbers going to end are not going to end in.

Divide the work into two. First, retrieve all href attribute content, use a regular expression for a dome parser such as PHP's docdict, and then to change the specific part. The advantage of this method on a regular expression is that Your markup format changes in the future, even if Shri it breaks.

  $ html = & lt; & Lt; & Lt; HTML & lt; A href = "/ upload / 2014/04 / draft-99 9 90-description doc" & gt; Draft 99 995 Details & lt; / A & gt; & Lt; A href = "/ upload / 2014/04/01090-vs-g1010-series pdf" & gt; 01095 vs G01015 series & lt; / A & gt; Html; $ Dom = new dome document; $ Dom- & gt; LoadHTML ($ HTML); $ Replacement = 'FOO'; $ Html = ''; Forex Currency ($ dom-> getElementsByTagName ('A') as the $$ node) {$ href = $ node- & gt; GetAttribute ('href'); $ Node- & gt; Set properties ('href', preg_replace ('/ ([a-z])? \ D {5} / i', $ substitution, $ href); $ Html $$ Dom-> Save HTML ($ node); } $ Html echo;  

Output:

  & lt; A href = "/ upload / 2014/04 / draft- FOO-details.doc" & gt; Draft 99 995 Details & lt; / A & gt; & Lt; A href = "/ upload / 2014/04 / FOO-vs-FOO-series.pdf" & gt; 01095 vs G01015 series & lt; / A & gt;  


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -