INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Regex for find and replace?  (Read 4384 times)

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Regex for find and replace?
« on: October 11, 2012, 09:58:09 am »

Hi all --

I'm stuck on MC's regex implementation. I think I'm used to simpler forms of it, i.e. TextWrangler. I can whack some cool stuff together there, but I'm missing out on MC's power. I'm trying to take a handful of files and alter the Name fields to have some text inserted at the beginning. If it were TextWrangler I'd just do a find for "(.*)" and replace with "[my text](/1)". I know MC's regex syntax is different, so there's that, but what I think where I'm stuck is how to actually edit the field. If I follow the wiki correctly, what I need to do is create another field and have it contain "[my text] [=Name]", and, after that, copy and paste those values back into the [Name] field. You'll forgive me for thinking this seems really inefficient and that there must be a better way. So, is there? What am I not understanding (as I'm sure there's something)?

Thanks very much --
Micah
Logged

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4889
Re: Regex for find and replace?
« Reply #1 on: October 11, 2012, 03:16:15 pm »

You can do this with MC's in-built expressions functionality.

In standard view, select the files you want to alter.
Right click on the top file's Name field and select Rename
Type:
=YourText [name]

Hit return. That should be it.

Apologies if I've completely misunderstood what you're trying to do.
Logged

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Re: Regex for find and replace?
« Reply #2 on: October 11, 2012, 03:20:30 pm »

You can do this with MC's in-built expressions functionality.

In standard view, select the files you want to alter.
Right click on the top file's Name field and select Rename
Type:
=YourText [name]

Hit return. That should be it.

Apologies if I've completely misunderstood what you're trying to do.

Aha! Perfecto! No, you've got what I wanted to do exactly. That is very easy, thanks. I should have guessed there was a faster way.  ::)

Any thoughts on using regex for find and replace while I have you here? :)

Thanks again!
Micah
Logged

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4889
Re: Regex for find and replace?
« Reply #3 on: October 11, 2012, 03:24:22 pm »

Aha! Perfecto! No, you've got what I wanted to do exactly. That is very easy, thanks. I should have guessed there was a faster way.  ::)

Any thoughts on using regex for find and replace while I have you here? :)

Thanks again!
Micah

Now I WILL have to apologise. I am a simpleton who has not had the time to learn any of the RegEx stuff. I do very simple, non-conditional, stuff with what MC has built-in.
There is, however, a pretty decent find and replace utility in MC, and if it has anything to do with filenames, there is a section in the Move,rename,copy files option.
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Regex for find and replace?
« Reply #4 on: October 11, 2012, 06:54:07 pm »

Any thoughts on using regex for find and replace while I have you here? :)

The Expression Language wiki is a good place to start: 6.4.12 Regex(...): Regular expression pattern matching and capture
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Regex for find and replace?
« Reply #5 on: October 11, 2012, 07:16:10 pm »

A while back, I had posted a screenshot mockup, or description of, or request for Regular Expression support in the Find and Replace section of the Rename dialog.  I spent 30 minutes looking, and failed to find it.
Logged
The opinions I express represent my own folly.

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Re: Regex for find and replace?
« Reply #6 on: October 20, 2012, 10:36:05 am »

A while back, I had posted a screenshot mockup, or description of, or request for Regular Expression support in the Find and Replace section of the Rename dialog.  I spent 30 minutes looking, and failed to find it.

Whoops, forgot to respond to this last week. (Saturday morning appears to be my time to hang out on MC boards.)

This, this right here, would be great. I mean, this is what it's all about, right?

Oh, and, rick.ca, sorry: the wiki is a poor place for beginners on this one. It's good as a reference or as intermediate knowledge, but not a good beginners' intro. To be honest, this is a problem I have with wikis for software in general: programmers see the world differently (it's ok, they know that ;) ), and I've found they tend to think a reference that lays all the information plain is the best way to start learning something. They can think about it that way. I cannot, I need a gradual introduction. But that's a whole other thread... Thanks though.

Micah
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Regex for find and replace?
« Reply #7 on: October 20, 2012, 05:58:42 pm »

Quote
Oh, and, rick.ca, sorry: the wiki is a poor place for beginners on this one.

Really? I can't think of a simpler, more concise explanation of how regex is implemented in MC. That's good, because beginner and expert alike need to know at least that much to make any use of regex anywhere in MC. It then goes on to illustrate some capabilities by way of straightforward examples. If you know of an approach more suitable for beginners, maybe you can persuade MrC to rewrite his wiki article. ;)

I stand by my original advice. The wiki is a good place to start for a gradual introduction. Having read it, one can decide whether they have the aptitude and time to learn how to use regex. One of the examples might be enough to illustrate how to satisfy a specific need. More likely, a deeper understanding of regex will be necessary. For that, there's lots of references, tutorials and tools on the Web—designed for beginners, experts and anyone in between.

An excellent reference/tutorial is Regular-Expressions.info. The most useful resource I have (after MrC, of course) is Expresso. Not being a programmer, I rely heavily on trial & error—regardless of how clear any reference is. Expresso is sort of a reference, tutorial, editor and tester rolled into one.
Logged
Pages: [1]   Go Up