View previous topic :: View next topic |
Author |
Message |
eidolen
Joined: 15 Apr 2008 Posts: 11
|
Posted: Sat Sep 05, 2009 7:10 pm Post subject: Help with exclusion regex |
|
|
Haven't been around for a while now so I think I got a little rusty. :\
I'm having trouble creating a regex that would apply to all *unless* it is enclosed by any type of bracket.
ie. change all Underscore marks with spaces unless that underscore is enclosed within brackets. I know I've done similar regex before, but now I'm just stumped.
Any help is much appreciated.
Cheers |
|
Back to top |
|
 |
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Mon Sep 07, 2009 3:36 am Post subject: |
|
|
Hi,
I can't think of an elegant way to do this. A crude way is shown below. To try it copy the search/replace expressions into the appropriate rows/columns (but don't copy the enclosing single quotes).
Row: 1
Search: '(.*)(\(.*?)_(.*\))(.*)'
Replace: '\1\2xxx\3\4'
Row: 2
Search: '(.*)(\(.*?)_(.*\))(.*)'
Replace: '\1\2xxx\3\4'
Row: 3
Search: '_'
Replace: ' '
Row: 4
Search: 'xxx'
Replace: '_'
The first row replaces the first '_' found within a set of parentheses with the characters xxx. The second row is identical and is used in case there is a second occurence. You can add repeat the row as many times as required.
WHen the third row executes, it is assumed that the only '_' characters left are outside any enclosing parentheses and therefore changes each '_ to a blank. The fourth row changes back the xxx's to '_'.
You can replace the xxx with another string if you want in case xxx can occur natually in the filenames.
Hope this helps.
Peter. |
|
Back to top |
|
 |
eidolen
Joined: 15 Apr 2008 Posts: 11
|
Posted: Mon Sep 07, 2009 11:35 am Post subject: |
|
|
Thanks Peter,
I ended up coming up with a similar solution but thought I was missing something obvious to do it one go. At least I don't feel so bad about myself now. =D
Hope you have a great holiday,
Cheers |
|
Back to top |
|
 |
|