Urban75 Home About Offline BrixtonBuzz Contact

Regular Expressions - God I love these things

AND - they have balloooooons at offline?! SINCE WHEN?! WHY WAS I NOT INFORMED!??!?!?!
 
(I hope) I'm not a proper geek but I think regular expressions are awesome. The language is genius. It's like a meaningful form of assembly, and crafting one is like building something out of matchsticks - one false move and the whole fucking thing won't make the slightest bit of sense any more and you'll have to start over again.
 
mauvais said:
(I hope) I'm not a proper geek but I think regular expressions are awesome. The language is genius. It's like a meaningful form of assembly, and crafting one is like building something out of matchsticks - one false move and the whole fucking thing won't make the slightest bit of sense any more and you'll have to start over again.


I think this puts it best, I concur!
 
This is from the opening post:
So: in praise of the regular expression.

'^(?P<stem>.*?)((?P<desc>(?P<flag>[~#])|(?P<brak>[\[]))(?P<suf>\d{1,2}))?(?(brak)[\]])(?P<ext>\.[^\.]*)?$'
It's frightening. Even now, two years down the line.

All I want to know is...

If I have an MP3 with a filename in the format:

ARTIST - ALBUM_TITLE (YEAR).mp3

.. how can I reformat it using regular expressions so that it reads:

ARTIST - YEAR - ALBUM_TITLE.mp3

Simple question with an, hopefully, simple answer.

Regular expressions baffle me. Replacement expressions especially baffle me.

Can anyone link me to a good Idiots Guide? All the ones I've read dive too deep too fast.

I'm familiar with some of the substitutions - ^ to represent start of line, $ for end of line, [0-9] = any digit, etc. - but I'm struggling to get beyond this meagre beginning. :(
 
Code:
s/^(.* - )(.*) \((\d+)\)(.*)$/$1$3 - $2$4/

I think
Blimey. If I'm using a file renamer that supports RE (can I call them RE?), does that lot all go in the Find box and the Replace box stays empty?

It all looks like double dutch to me. :(

I think I'm going to have to buy a book on this, as I know that they're potentially extremely useful..
 
I changed it slightly just in case you have some crap in your fields. Sure, a file renamer that supports standard regexps should do it.
 
I got really excited because I thought Kameron and SubZeroCat were posting again....

...and then I saw that it was a mega-bump. :(

...that doesn't make any sense. :( :(
 
Is there a very very simple way of explaining to a computer idiot what a regular expression is & why it's good? :confused: :confused:
It's good for (a) batch renaming files, and (b) performing complex text edits without manually going through and changing everything.

You won't need to know anything about them until you find a need to know all about them. :)
 
It's good for (a) batch renaming files, and (b) performing complex text edits without manually going through and changing everything.

You won't need to know anything about them until you find a need to know all about them. :)

I will never find a need to know all about them (she said, with her fingers crossed! :eek:)

thank you. :)
 
I did escape my parentheses! The ones I _wanted_ to escape, anyway....
Is there a very very simple way of explaining to a computer idiot what a regular expression is & why it's good?
I'll give it a shot. You know "find & replace"? Well, whetever you put into the "find" box is a very dumb regular expression. You're trying to match a certain combination of letters (and then, maybe, replace them with something else).

The expression s/kitten/walrus/ is really like "find the text kitten, replace it with the text horse", it's just all on one line.

A regular expression is really just a much more powerful way of finding things. So, say you have lots of text like "the fluffy kitten", "the ginger kitten", "the <something> kitten" and you want to replace all of those with "the walrus". A full stop means "any character", and a * means "any number of whatever the previous thing was". So, you could say

s/the .* kitten/the walrus/

and that would do the trick, it would look for "the " followed by any number of crap characters followed by " kitten", and replace the whole thing with "the walrus".

You can get a lot more complicated than that, looking for ranges or characters, specifying alternative patterns and so on, but it's basically just a language that lets you specify patterns of characters. Very long and complex ones. You can also "tag" bits of the pattern you find with brackets, and use those in the replacement, so s/My name is (.*)!/Call me $1./ would replace "My name is <whatever>!" with "Call me <whatever>." But the basic point of regular expressions is the pattern matching part.
 
Interesting. I am learning, slowly.

Tried your MP3-renaming string. Didn't work. :)

It's not important, though - it was just an example of a problem I regularly come across where a nice regular expression could help.

Next step I think is to buy an idiot's guide (and become a regular expression ninja). Can anyone recommend one?
 
Back
Top Bottom