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条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备