正则表达式:如何在单词之间找到破折号 [英] Regular Expressions: How to find dashes between words

查看:56
本文介绍了正则表达式:如何在单词之间找到破折号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PCRE中如何找到单词之间的破折号

In PCRE how to find dashes between words

例如

第一个文件-111-222.txt
这是第二个文件-123-456.txt
And-the-last-one-66-77.txt

First-file-111-222.txt
This-is-the-second-file-123-456.txt
And-the-last-one-66-77.txt

所以,First 和 File(等)之间的破折号

So, the dash between First and and File (etc)

然后我可以用空格替换它们.

Then I could replace them with a space.

使用 ([^a-zA-Z]\d(.+)) 我可以选择最后一部分(破折号+nbrs)但我不知道如何标记其他破折号.

With ([^a-zA-Z]\d(.+)) I could select the last part (dash+nbrs) but I don't know how to mark the other dashes.

==编辑这个想法是使用重命名工具(支持正则表达式) - 然后重命名会导致

== edit the idea is to use a renamer tool (supporting regular expressions) - the rename would then to result in

第一个文件-111-222.txt
这是第二个文件-123-456.txt
还有最后一个-66-77.txt

First file-111-222.txt
This is the second file-123-456.txt
And the last one-66-77.txt

所以,在最后一个单词之后和数字之间的 - 要保持原位.只替换单词之间的那些.

so, the - after the last word and between the numbers to be kept in place. only the ones between words to be replaced.

推荐答案

使用环顾四周:

(?i)(?<=[a-z])-(?=[a-z])

这匹配前面有一个字母和后面有一个字母的破折号.

This matches dashes that have a letter preceding and a letter following.

这篇关于正则表达式:如何在单词之间找到破折号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆