如何在 RegEx 中找到其余字符串包含第一个 B 的最后一个 A?
How to find the last A that the rest string contains the first B in RegEx?
我有大量的文件需要改名,其中名字包含乱码post修复。我正在使用一些高级重命名软件,想知道如何编写一个 RegEx 来删除 postfix。一些例子是:
Content - Still content-A pOst fix
Content-- BpOst - fix with - inside (dashes in postfix)
Content-Still --Content -CpOstfix (dashes in content)
Content fake pOst - real pOst --fix (two keywords, one in content and postfix each)
Content fake- pOst - real pOst --fix (two keywords both in postfix)
Content fake pOst fix (space is not a splitter of pOstfix, so nothing removed)
我希望输出删除所有 post 修复,包括前导破折号 and/or space。期望的输出是:
Content - Still content
Content
Content-Still --Content
Content fake pOst
Content fake
Content fake pOst fix (space is not a splitter of pOstfix, so nothing removed)
我什至不知道这是否可以通过 RegEx 实现。
不确定数量的破折号(带或不带 space)是 post 修复的拆分器,但内容或 post 修复可能包含破折号 and/or 修复,但是说,所有 post 修复都包含某个字母(例如本例中的字母 O
或 pOst
)。
有几点:
- content 和 postfix 之间的分隔符只有破折号,如果只有 space,则不是分隔符。
- 破折号和 spaces 可能同时包含在内容和 postfix 中,所以我不能简单地搜索 first/last 破折号作为分隔符 - 它是最后一个破折号,包括前导space(s),在第一次出现特定字母之前(见最后一个例子)。
- 我想找到一种编写单个 RegEx 表达式的方法,而不是逐渐删除 post修复程序。
- 整个文件名可能包含非 ASCII 字符,尤其是
certain letter(s)
。所以使用 [a-zA-Z]
. 这样的东西并不理想
PS: 我也想知道class包含A但不包含B的字符怎么写?
例如,我想要所有字母数字,但不包括字母 a 和数字 5,例如(显然行不通):/[\w^a5]+/
。除了像/[b-zA-Z0-46-9]/
这样写一个详尽的列表,还有什么更好的方法吗?喜欢并集和交集?
非常感谢您的帮助。非常感谢。
你应该可以替换
\s*-+\s*[^O-]*O.*$
空字符串。它将匹配一个或多个破折号(由可选空格包围),然后在输入结束前至少跟一个 O
。
如果您想匹配整个短语,您需要像这样使用 negative lookahead:
\s*-+\s*((?!pOst)[^-])*pOst.*$
我有大量的文件需要改名,其中名字包含乱码post修复。我正在使用一些高级重命名软件,想知道如何编写一个 RegEx 来删除 postfix。一些例子是:
Content - Still content-A pOst fix
Content-- BpOst - fix with - inside (dashes in postfix)
Content-Still --Content -CpOstfix (dashes in content)
Content fake pOst - real pOst --fix (two keywords, one in content and postfix each)
Content fake- pOst - real pOst --fix (two keywords both in postfix)
Content fake pOst fix (space is not a splitter of pOstfix, so nothing removed)
我希望输出删除所有 post 修复,包括前导破折号 and/or space。期望的输出是:
Content - Still content
Content
Content-Still --Content
Content fake pOst
Content fake
Content fake pOst fix (space is not a splitter of pOstfix, so nothing removed)
我什至不知道这是否可以通过 RegEx 实现。
不确定数量的破折号(带或不带 space)是 post 修复的拆分器,但内容或 post 修复可能包含破折号 and/or 修复,但是说,所有 post 修复都包含某个字母(例如本例中的字母 O
或 pOst
)。
有几点:
- content 和 postfix 之间的分隔符只有破折号,如果只有 space,则不是分隔符。
- 破折号和 spaces 可能同时包含在内容和 postfix 中,所以我不能简单地搜索 first/last 破折号作为分隔符 - 它是最后一个破折号,包括前导space(s),在第一次出现特定字母之前(见最后一个例子)。
- 我想找到一种编写单个 RegEx 表达式的方法,而不是逐渐删除 post修复程序。
- 整个文件名可能包含非 ASCII 字符,尤其是
certain letter(s)
。所以使用[a-zA-Z]
. 这样的东西并不理想
PS: 我也想知道class包含A但不包含B的字符怎么写?
例如,我想要所有字母数字,但不包括字母 a 和数字 5,例如(显然行不通):/[\w^a5]+/
。除了像/[b-zA-Z0-46-9]/
这样写一个详尽的列表,还有什么更好的方法吗?喜欢并集和交集?
非常感谢您的帮助。非常感谢。
你应该可以替换
\s*-+\s*[^O-]*O.*$
空字符串。它将匹配一个或多个破折号(由可选空格包围),然后在输入结束前至少跟一个 O
。
如果您想匹配整个短语,您需要像这样使用 negative lookahead:
\s*-+\s*((?!pOst)[^-])*pOst.*$