Replace space then hyphen then blank space

A swapping-ground for Regular Expression syntax

Replace space then hyphen then blank space

Postby Neil Jones » Tue Jan 14, 2014 1:58 am

Using RegexPal 0.1.4 — a JavaScript regular expression tester, I get this to work and it recognizes what I want: space, hyphen, space: \s[-]\s

In BRU I want to replace \s[-]\s with an underscore. I put \s[-]\s in RegEx 1 Match.

I put \_ in Replace. It doesn't work. What am I doing wrong?

I can do this with Character Translations by entering:

,-, =_


I would rather do this with Regular Expressions. Can it be done?
Neil Jones
 
Posts: 13
Joined: Thu Jan 09, 2014 10:01 am

Re: Replace space then hyphen then blank space

Postby Stefan » Tue Jan 14, 2014 8:10 am

Neil Jones wrote: What am I doing wrong?


Not reading my answers.

With BRU you have to match the whole file name by your regex expression, not parts only.






Please wait a few seconds then submit. Thank you.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Replace ALL Space-Space with _

Postby truth » Tue Jan 14, 2014 9:08 am

You can do it via regex, but each ocurrence of Space-Space must be matched.
So unless your files all have the same # of Space-Space's, multiple regexes are required:

.*( - ).* matches 1 occurence .*( - ).*( - ).* matches 2 occurences, & so forth.
Theres no 'global-match' feature via regex.

CharTrans is your best bet when you have multiple TextStrings to be translated.
You might prefer #3Replace instead, since this setting can be saved if you need it often.
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay

Re: Replace space then hyphen then blank space

Postby Neil Jones » Tue Jan 14, 2014 9:47 am

Stefan wrote:
Neil Jones wrote: What am I doing wrong?


Not reading my answers.

With BRU you have to match the whole file name by your regex expression, not parts only.



I'm reading your answers but I don't always comprehend them on the first go around or even the second go around. I'll try harder. I'm just beginning to start comprehending what the limitations of BRU are. I'm currently trying to understand exactly what this whole file name limitation when using RegEx really means and if workarounds will be a major PITA.

I just downloaded dn4b.com ReNamer and I like how it works and think it will make me much better at RegEx. I've already created several rules like I wanted to in BRU and they work. That makes me happy. :D I really like the logical approach used by ReNamer with how you apply rules and how easy it is to change the order of your rules. How the program works fits how my head thinks.
Neil Jones
 
Posts: 13
Joined: Thu Jan 09, 2014 10:01 am

Re: Replace ALL Space-Space with _

Postby Neil Jones » Tue Jan 14, 2014 10:35 am

truth wrote:You can do it via regex, but each ocurrence of Space-Space must be matched.
So unless your files all have the same # of Space-Space's, multiple regexes are required:

.*( - ).* matches 1 occurence .*( - ).*( - ).* matches 2 occurences, & so forth.
Theres no 'global-match' feature via regex.

CharTrans is your best bet when you have multiple TextStrings to be translated.
You might prefer #3Replace instead, since this setting can be saved if you need it often.


In CarTrans I can get it to work by adding this: ,-, =_

Using RegEx(1) I enter .*( - ).* for Match and \_ for Replace and it doesn't work. Neither does \s[-]\s for Match and \_ for Replace. The latter works just fine in dn4b.com ReNamer

What am I missing here?

"You might prefer #3Replace instead, since this setting can be saved if you need it often."

Good idea. Should have thought of that before. :oops:
Neil Jones
 
Posts: 13
Joined: Thu Jan 09, 2014 10:01 am

(Group) all text that should be kept

Postby truth » Wed Jan 15, 2014 1:30 am

The examples I gave are a bit misleading, since only Space-Space was grouped (replaceable).
Non-grouped text cannot be input into the replacement (with \1, \2, etc) & is thus dropped!

For BRU to match/replace ONE occurence of Space-Space, you would prob want:
1Regex Match/Replace
(.*)( - )(.*)
\1_\3

You dont need to group Space-Space when you're going to omit/replace it:
(.*) - (.*)
\1_\2

Both work identically, but again, they only replace 1 occurrence of Space-Space (the final one).
It would take multiple-regexes (or multiple-runs of the same regex) to match varying #'s of repeating Space-Space's
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay


Return to Regular Expressions