List Info

Thread: Regex to search for and replace file names




Regex to search for and replace file names
user name
2006-03-27 01:36:19
I'm attempting to use regex in bulk file renaming software.
I have
files with names like "000901-030" and I'm
trying to get rid of the
extra zeros, but save the needed ones. The result I'm
trying to get in
this example is "901-30"

I thought perhaps something like ([^0*])([1-9])(\-) might
find the
zeros before the first number,  with a replace of \1.  I'm
obviously
missing something. Any advise on a more effective regex
would be
greatly appreciated. Also, if anyone had a link
recomendation to the
best regex info site that would also help.

Thanks in advance for any info.

Cheers,

dputz


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Regex to search for and replace file names
user name
2006-03-27 12:31:01
[^0*] is a char class (meaning of []) which searches for any
char that
is NOT (meaning of ^ in []) either zero or asterisk.

A solution without lookahead would be

^0*([^0].*)

an replace with \1
Aside: This will not match if the filename consists entirely
of zeros!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Regex to search for and replace file names
user name
2006-03-27 12:37:49
Hi,

Sergei's solutions can usually be used straightaway without
any
problems, but in this case, I have the honour of making a
correction



What dputz needs is :


1. Find all zeros at the start of string, followed by any
digit.
(Positive lookbehind)
2. Find all zeros followed by a hyphen, followed by any
digit.
(Positive lookbehind, then Positive Lookahead)


He needs to replace 000901-030 with 901-30, NOT 901-03.


So, the Regex can be amended to :
^(0+)(?<=\d)|(?<=-)0(?=\d)


Regards, 


Cerebrus.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Regex to search for and replace file names
user name
2006-03-27 15:37:07
yes, guys, i miserably misunderstood the spec! . Thanks
for posting
right solutions.

Sergei


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Regex to search for and replace file names
user name
2006-03-27 22:38:08

Sergei Z wrote:
> yes, guys, i miserably misunderstood the spec! . Thanks
for posting
> right solutions.
> 
> Sergei


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )