私は正規表現が苦手なので、助けが必要です。
以下にリンクリンクがあります:
http://www.mydomain.com/1/1/5/1/some-name-123-115194_7_9.jpg
以下のようなphpで取得する正規表現は何ですか:
これは私がこれまでに試したことです:
preg_match_all('/(\d+)(\w+)/', $str,$matches);
私は正規表現が苦手なので、助けが必要です。
以下にリンクリンクがあります:
http://www.mydomain.com/1/1/5/1/some-name-123-115194_7_9.jpg
以下のようなphpで取得する正規表現は何ですか:
これは私がこれまでに試したことです:
preg_match_all('/(\d+)(\w+)/', $str,$matches);
使用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