dscdttg4389 2011-07-17 14:49
浏览 61
已采纳

用preg_match替换括号中的引号和单词?

I'm struggling to match a few movie titles i have in a weird format. Some of the titles are wrapped in quotes and some begin with # or $, and most of them end with the release year at the end (otherwise ????).

I'm trying to replace this:

"Ein Engel für alle" (2005) {Katzenjammer (#2.5)}   ????
#"Sospecha" (1963) {El caso del viejo del Tibet}     1963
MTV Europe Music Awards 1998 (1998) (TV)        1998
"Hotel Cæsar" (1998) {(#12.26)}             1998
$Am Rande - Sechs Kapitel über AIDS in der Ukraine (2006)   2006

...to this:

Ein Engel für alle, ????
Sospecha, 1963
MTV Europe Music Awards 1998, 1998
Hotel Cæsar, 1998
Am Rande - Sechs Kapitel über AIDS in der Ukraine, 2006

...and if possible, get the release year somehow. In the example I just put a comma, but if you can't get the release date just leave it and I'll get it another way.

I'm a complete newbie in regular expressions but I still tried to do it with no luck. If anyone can give me a hand I'd really appreciate it!


Edit

To make it less confusing:

  1. Remove everything wrapped in () or {}.

  2. Remove the $ or # in the beginning of the string.

  3. IF the title is wrapped in quotes, remove them.

  4. Either leave it like this, or use some kind of grouping to get the release date at the end of the string to a separate variable?

Hope this helps :)

  • 写回答

4条回答 默认 最新

  • douzengjian1535 2011-07-17 14:53
    关注

    The regexp should be

    $regexp = '[\W]*([\w- üæöä]+)[\W^-].*([\d?]{4})';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案