Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expressions: How to find dashes between words

Tags:

regex

pcre

In PCRE how to find dashes between words

e.g.

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

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

Then I could replace them with a space.

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

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.

like image 337
user2243577 Avatar asked Oct 31 '25 17:10

user2243577


1 Answers

If I'm not missing anything following regex should work for you:

(?<=\D)-(?=\D)

It just means find a hyphen char if it is between 2 non-digit characters.

Live Demo: http://www.rubular.com/r/O2XUNaB02R

like image 110
anubhava Avatar answered Nov 03 '25 15:11

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!