DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: help ! With RegEx  (Read 6,928 times)

Armando

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 2,727
    • Coding Snacks
help ! With RegEx
« on: July 04, 2008, 05: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.
"I suppose it can be said that I'm an absent-minded driver. It's true that I've driven through a number of red lights on occasion, but on the other hand, I've stopped at a lot of green ones but never gotten credit for it."
Glenn Gould
« Last Edit: July 04, 2008, 05:09 AM by Armando »

housetier

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,321
    • Gathering Badge
Re: help ! With RegEx
« Reply #1 on: July 04, 2008, 08:45 AM »
Using http://rubular.com I get as far as
Code
(\.)
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
Code
(?<...)
or
Code
(?>...)
.

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

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: help ! With RegEx
« Reply #2 on: July 04, 2008, 08:56 AM »
Code
(.*__)(?:(.*?)(:?\.)(.*?))(__.*)
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
    • Coding Snacks
Re: help ! With RegEx
« Reply #3 on: July 04, 2008, 03:05 PM »
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
Code
(?<...)
or
Code
(?>...)
.

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...  :)

Code
(.*__)(?:(.*?)(:?\.)(.*?))(__.*)
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...)
"I suppose it can be said that I'm an absent-minded driver. It's true that I've driven through a number of red lights on occasion, but on the other hand, I've stopped at a lot of green ones but never gotten credit for it."
Glenn Gould

Armando

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 2,727
    • Coding Snacks
Re: help ! With RegEx
« Reply #4 on: July 04, 2008, 04:12 PM »
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.
"I suppose it can be said that I'm an absent-minded driver. It's true that I've driven through a number of red lights on occasion, but on the other hand, I've stopped at a lot of green ones but never gotten credit for it."
Glenn Gould

Original address: https://www.donationcoder.com/forum/index.php?topic=13945.0