Home>

I am using a regular expression to extract the image ID from the wordpress img tag, but if the img tags are continuous without sandwiching anything, it will be the longest match.
I was wondering if I should use?, But it didn't work out, and I hope I can borrow my wisdom.

Regular expression: //i
Target:  
Expected results: 38, 36
  • Answer # 1

    This kind of thing should be processed properly in the DOM

  • Answer # 2

    Is it like this?

    <? php
    preg_match_all (
        '/ wp-image-(\ d +) /',
        ' ',
        $matches,
        PREG_PATTERN_ORDER
    );
    print_r ($matches [1]);
    ?>
    Output result
    Array
    (
        [0] =>38
        [1] =>36
    )