-1

私は正規表現が苦手なので、助けが必要です。

以下にリンクリンクがあります:

http://www.mydomain.com/1/1/5/1/some-name-123-115194_7_9.jpg

以下のようなphpで取得する正規表現は何ですか:

http://www.mydomain.com/1/1/5/1/115194_7_9.jpg

これは私がこれまでに試したことです:

preg_match_all('/(\d+)(\w+)/', $str,$matches); 
4

1 に答える 1

1

使用preg_replace:

$url = "http://www.mydomain.com/1/1/5/1/some-name-123-115194_7_9.jpg";

echo preg_replace('#(.+/).+-(.+)#','$1$2',$url)

>>> http://www.mydomain.com/1/1/5/1/115194_7_9.jpg

説明:

(.+/)   # Match everything upto the last / and capture
.+-     # Match upto the last -
(.+)    # Match and capture everything else 
        # Replace with 
$1$2    # The first and second capture groups
于 2012-12-13T16:52:44.013 に答える