复杂的正则表达式匹配字符集之间的所有内容?

时间:2014-03-24 02:11:13

标签: regex

正则表达式!这不适用于特定语言。这是一个多文件重命名器,可以让你使用正则表达式。所以我只是在寻找一个“纯粹的”正则表达式解决方案。我找不到合适的答案,所以我想我会问。

以下是我正在使用的各种字符串的示例:

[998FA551B]-[FIRE]-[#b.c.friends@fams]-[ My.Life.Story.V99A4.NONE.x4X5p-RIEP ]- my.life.story.v99a4.xrsr-riep

我需要的是删除' - ['和'] - '或'破折号,左括号,空格'和'空格,近括号,短划线'之间的的所有内容留下:

My.Life.Story.V99A4.NONE.x4X5p-RIEP

谢谢!

2 个答案:

答案 0 :(得分:1)

匹配目标之外的所有内容:

^.*-\[ | \]-.*$

然后用空白替换匹配以删除。

See live demo此正则表达式使用您的示例输入。

答案 1 :(得分:1)

您可以使用此正则表达式来捕获名称:

-\[\s(.+)\s\]-

匹配示例:My.Life.Story.V99A4.NONE.x4X5p-RIEP

<强>故障:

-           # match the literal dash
\[          # match the opening square bracket (\ escape required)
\s          # match a single whitespace
(           # open capture group
    .+      # match anything at least once ()
)           # close capture group
\s          # match a single whitespace
\]          # match the closing square bracket (\ escape required)
-           # match the literal hash

演示: http://regex101.com/r/fT7fI3

相关问题