phpregex获取一本书的名称和作者


php regex get name and author of a book

我有一些书名类似于

lastname, firstname - bookname.extension
firstname lastname - bookname.extension

我想使用php正则表达式将这种格式更改为

bookname-名字姓氏扩展

我希望有一种简单的方法可以制作一个regex来提取一个包含firstname、lastname、author和扩展名的数组。

说出我的解决方案

<?php 
$book = "Alfred, Zusak - Time of the death.pdf";
$book = preg_replace("#^([a-zA-Z0-9-_. ]+)',([a-zA-Z0-9-_. ]+)'-([a-zA-Z0-9-_. ]+)'.([a-zA-Z0-9-_.]+)$#isU", "$3 - $2 $1.$4", $book);
echo $book;
?>