topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday April 16, 2024, 2:52 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: help ! With RegEx  (Read 5248 times)

Armando

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 2,727
    • View Profile
    • Donate to Member
help ! With RegEx
« on: July 04, 2008, 12:06 AM »
OK. I'm ignorant in that matter.

I have a bunch of file names looking like that :

xLC-(2003).Someones,Name.__ The Greatest. Book.In.the World 12345__+tgsPma tgsPorgn+.doc


I'm trying to get rid of the "." inside inside the pairs of "__".

How can I define that area comprised between both "__" (__that area__) so that I don't remove any "." situated outside of these?




PS : With my renamer (Flash Renamer), I tried all kinds of simplistic combinations like :

Find:
(.__)(\w*+\s*)(\.*)(__\+)
And replace with
$1$2$4

.. to match all "." inside the "__"

Obviously, it won't work... I know.
« Last Edit: July 04, 2008, 12:09 AM by Armando »

housetier

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 1,321
    • View Profile
    • Donate to Member
Re: help ! With RegEx
« Reply #1 on: July 04, 2008, 03:45 AM »
Using http://rubular.com I get as far as
(\.)

giving me all the dots.

There is something like assertions in regular expressions, where you can say "give me this if not followed by that" or "give me this if it comes after that". however, these don't seem to be available on rubular.com. IIRC, assertions look like
(?<...)
or
(?>...)
.

Then I sometimes get the feeling there are different flavors of regular expressions, while I am under the impression there would be a standard: PCRE. This feeling is amplified when I start redet and see all the different "programs" it can use for matching.

However, with my lack of patience I couldn't find a regular expression that matches all "." in between "__". Maybe someone else will :)


jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: help ! With RegEx
« Reply #2 on: July 04, 2008, 03:56 AM »
(.*__)(?:(.*?)(:?\.)(.*?))(__.*)
I think the above works (at least, i got to work with rereplace.com), but you'll have to do it several times because it only removes one dot at a time.

(replacement: "$1$2 $4$5" or "$1$2 $3$4")

Armando

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 2,727
    • View Profile
    • Donate to Member
Re: help ! With RegEx
« Reply #3 on: July 04, 2008, 10:05 AM »
Thanks guys -- and thanks for the links.

There is something like assertions in regular expressions, where you can say "give me this if not followed by that" or "give me this if it comes after that". however, these don't seem to be available on rubular.com. IIRC, assertions look like
(?<...)
or
(?>...)
.

Thanks I'll have to look into these assertions!


Then I sometimes get the feeling there are different flavors of regular expressions, while I am under the impression there would be a standard: PCRE. This feeling is amplified when I start redet and see all the different "programs" it can use for matching.

However, with my lack of patience I couldn't find a regular expression that matches all "." in between "__". Maybe someone else will :)

I understand...  :)

(.*__)(?:(.*?)(:?\.)(.*?))(__.*)
I think the above works (at least, i got to work with rereplace.com), but you'll have to do it several times because it only removes one dot at a time.

(replacement: "$1$2 $4$5" or "$1$2 $3$4")

Yes, thanks alot, it works. As you said, I'll have to do it several times. Which I'll do.
(Only as a learning experience, I was wondering if it was possible to get all these "." inside "__". But...)

Armando

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 2,727
    • View Profile
    • Donate to Member
Re: help ! With RegEx
« Reply #4 on: July 04, 2008, 11:12 AM »
I actually modified jgpaiva'ssolution to the slightly different

(.*)(__)(?:(.*?)(:?\.)(.*?))(__)(.*)
$1$2$3 $5$6$7

FlashRenamer didn't want to accept the other one with (.*__) instead. Go figure.