试试这个
(?i)("[^"]+") +([a-z]+) +(\-[a-z]+)\b
代码
if (preg_match('/("[^"]+") +([a-z]+) +(-[a-z]+)\b/i', $subject, $regs)) {
$howto = $regs[1];
$engine = $regs[2];
$fuel = $regs[3];
} else {
$result = "";
}
解释
"
(?i) # Match the remainder of the regex with the options: case insensitive (i)
( # Match the regular expression below and capture its match into backreference number 1
\" # Match the character “\"” literally
[^\"] # Match any character that is NOT a “\"”
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
\" # Match the character “\"” literally
)
\ # Match the character “ ” literally
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
( # Match the regular expression below and capture its match into backreference number 2
[a-z] # Match a single character in the range between “a” and “z”
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
\ # Match the character “ ” literally
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
( # Match the regular expression below and capture its match into backreference number 3
\- # Match the character “-” literally
[a-z] # Match a single character in the range between “a” and “z”
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
\b # Assert position at a word boundary
"
希望这可以帮助。