php正则表达式-清除文件名

php正则表达式-清除文件名,php,regex,preg-replace,Php,Regex,Preg Replace,我正在寻找优雅的正则表达式,以清除括号,内容看起来像文件名 [Nibh justo] elit Nulla [link.pdf] auctor ipsum molestie (link.pdf) Condimentum euismod non [link.xls](link.xls) [link.doc](link.doc) tempus In [Curabitur] et 结果应该是: Nibh justo elit Nulla auctor ipsum molestie Condim

我正在寻找优雅的正则表达式,以清除括号,内容看起来像文件名

[Nibh justo] elit Nulla [link.pdf]  auctor ipsum molestie (link.pdf) 
Condimentum euismod non [link.xls](link.xls) [link.doc](link.doc) tempus 
In [Curabitur] et
结果应该是:

Nibh justo elit Nulla auctor ipsum molestie Condimentum euismod 
non tempus In Curabitur et
我相信一定有一条捷径可以做到这一点。 (文件的意思是简单-包括点。不需要检查句子。)

谢谢你的帮助像这样的事

$str = '[Nibh justo] elit Nulla [link.pdf]  auctor ipsum molestie (link.pdf) 
Condimentum euismod non [link.xls](link.xls) [link.doc](link.doc) tempus In 
[Curabitur] and other [./beta/link.pfd]';

$str = preg_replace('`(\(|\[)[\w/\.-]+\.[a-z]+(\)|\])`i', '', $str);
$str = str_replace(array('[', ']'), '', $str);

echo $str;
结果是:

Nibh justo elit Nulla auctor ipsum molestie Condimentum euismod 
non tempus In Curabitur and other

试试这个:

    <!--
(?:[\[\(]\w+\.\w+[\]\)])|(?:[\[\(](?=[0-9A-Za-z]))|(?:(?<=[0-9A-Za-z])[\]\)])

Options: ^ and $ match at line breaks

Match either the regular expression below (attempting the next alternative only if this one fails) «(?:[\[\(]\w+\.\w+[\]\)])»
   Match the regular expression below «(?:[\[\(]\w+\.\w+[\]\)])»
      Match a single character present in the list below «[\[\(]»
         A [ character «\[»
         A ( character «\(»
      Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
         Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
      Match the character “.” literally «\.»
      Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
         Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
      Match a single character present in the list below «[\]\)]»
         A ] character «\]»
         A ) character «\)»
Or match regular expression number 2 below (attempting the next alternative only if this one fails) «(?:[\[\(](?=[0-9A-Za-z]))»
   Match the regular expression below «(?:[\[\(](?=[0-9A-Za-z]))»
      Match a single character present in the list below «[\[\(]»
         A [ character «\[»
         A ( character «\(»
      Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=[0-9A-Za-z])»
         Match a single character present in the list below «[0-9A-Za-z]»
            A character in the range between “0” and “9” «0-9»
            A character in the range between “A” and “Z” «A-Z»
            A character in the range between “a” and “z” «a-z»
Or match regular expression number 3 below (the entire match attempt fails if this one fails to match) «(?:(?<=[0-9A-Za-z])[\]\)])»
   Match the regular expression below «(?:(?<=[0-9A-Za-z])[\]\)])»
      Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) «(?<=[0-9A-Za-z])»
         Match a single character present in the list below «[0-9A-Za-z]»
            A character in the range between “0” and “9” «0-9»
            A character in the range between “A” and “Z” «A-Z»
            A character in the range between “a” and “z” «a-z»
      Match a single character present in the list below «[\]\)]»
         A ] character «\]»
         A ) character «\)»
-->

(?:[\[\(]\w+\.\w+[\]\))))(?:[\[\(?=[0-9A-Za-z])))(?:(?:(?是的。效果很好,但
库拉比图
仍然丢失。看起来它与括号中的单个单词不匹配。请尝试以下操作:
(?:[\[\[\(]\w+.\w+.\w+[\]))))))(?:[\[\(?=[0-9A-Za-z]):(?感谢您的帮助。虽然文件链接包含dirs,但存在许多不匹配,但在创建expr时它有帮助。如果您需要匹配带或不带dirs的
文件名
,则正则表达式可能比现在发布的更简单!
[Nibh justo] elit Nulla [link.pdf]  auctor ipsum molestie (link.pdf) 
Condimentum euismod non [link.xls](link.xls) [link.doc](link.doc) tempus 
In [Curabitur] et
Nibh justo elit Nulla   auctor ipsum molestie  
Condimentum euismod non   tempus 
In Curabitur et