Capturing a pattern of unknown repitition in PCRE

前端 未结 2 1150
猫巷女王i
猫巷女王i 2020-12-11 23:52

This may be a quick question for experienced regular expressionists, but I\'m having trouble getting my match to execute correctly.

Suppose I had a string that looke

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 00:47

    If you want the items in the subdomain, and then all matches between the dashes... This should work:

    $string = "http://aaa-bbbb-cc-ffffffffd-eee-.sub.dom";
    
    preg_match("/^http:\/\/([\w-]+?)\..*$/i", $string, $match);
    
    $parts = explode('-', $match[1]);
    
    print_r($parts);
    

    Short of that you will probably have to build a small parsing script to parse the string yourself if that doesn't do it for you.

提交回复
热议问题