Regular Expressions do not work in my BRU. Period.

A swapping-ground for Regular Expression syntax

Regular Expressions do not work in my BRU. Period.

Postby opusthepenguin » Tue Dec 24, 2013 11:48 pm

I can't figure out what's wrong. It's not that I can't get regular expressions to work RIGHT. They simply do not work in my 64-bit BRU ver 2.7.1.2. At all. I have tried the example in the help file:

Assume you have a file called Program Files, and you wish to swap the names around (e.g. Files Program). A Regular Expression which performs this task is :

^([A-Z][a-z]*) ([A-Z][a-z]*)

Let us break this down into components:

^ This means start at the beginning of the string

([A-Z][a-z]*) This is a single "group", which we will use later. What this says is that we want any capital letter, followed by any number of lower-case letters. The single capital letter is denoted by the [A-Z], i.e. allow a letter in the range A to Z. The lower-case letters are denoted by [a-z] in the same way, followed by an asterisk. This means we can allow any number of letters.

We then allow a single space. If I had wanted multiple spaces I would probably have typed "space asterisk", or possible ( *) to group.

We then have exactly the same again, i.e. we are denoting two words.

Notice we had two sets of brackets. Everything within each set of brackets is treated as a "grouping", and we refer to these groupings as \1, \2, \3 etc.

So, lets say we wanted to swap around the two words in the filename. We would put:

^([A-Z][a-z]*) ([A-Z][a-z]*)

For the match string, and

\2 \1

As the replacement string. Of course, we're free to manipulate the replacements string as we like. For example, it would be quite valid to have:



I created a file called "program files" just so I could have EXACTLY the same thing being talked about. I copied and pasted ^([A-Z][a-z]*) ([A-Z][a-z]*) into the Match field. The title RegEx(1) immediately turned red. I copied and pasted \2 \1 into the Replace field. Here's what I got.

Image

You will note that the file "program files" has not changed its name to "files program".

I have looked at other RegEx examples in this discussion group. I have copied and pasted several that supposedly work. No matter what, BRU will not recognize any of them and will not rename files using them.

I have reinstalled BRU.

What am I doing wrong?
opusthepenguin
 
Posts: 1
Joined: Tue Dec 24, 2013 11:18 pm

Regular Expressions do work fine in my BRU. Period.

Postby Stefan » Wed Dec 25, 2013 12:30 am

opusthepenguin wrote:What am I doing wrong?
Not learning RegEx first?



opusthepenguin wrote: "I created a file called "program files" just so I could have EXACTLY the same thing being talked about."


No! You don't. The quoted help speak about "Program Files", isn't it?

See, "A-Z" means: one piece of an upper case char from the range A,B,C,......Z

Question: where is an an upper case char in your example "program files" ?







Note

BRU supports RegEx but the documentation is not the best possible. Search for another RegEx tutorial (see first post in this sub forum)

You may want to open an new thread by posting a few example file names of your renaming issue and where you got an problem...






- - -






opusthepenguin wrote:I can't figure out what's wrong. It's not that I can't get regular expressions to work RIGHT. They simply do not work in my 64-bit BRU ver 2.7.1.2. At all. I have tried the example in the help file:

Assume you have a file called Program Files, and you wish to swap the names around (e.g. Files Program). A Regular Expression which performs this task is :

^([A-Z][a-z]*) ([A-Z][a-z]*)

Let us break this down into components:

^ This means start at the beginning of the string

([A-Z][a-z]*) This is a single "group", which we will use later. What this says is that we want any capital letter, followed by any number of lower-case letters. The single capital letter is denoted by the [A-Z], i.e. allow a letter in the range A to Z. The lower-case letters are denoted by [a-z] in the same way, followed by an asterisk. This means we can allow any number of letters.

We then allow a single space. If I had wanted multiple spaces I would probably have typed "space asterisk", or possible ( *) to group.

We then have exactly the same again, i.e. we are denoting two words.

Notice we had two sets of brackets. Everything within each set of brackets is treated as a "grouping", and we refer to these groupings as \1, \2, \3 etc.

So, lets say we wanted to swap around the two words in the filename. We would put:

^([A-Z][a-z]*) ([A-Z][a-z]*)

For the match string, and

\2 \1

As the replacement string. Of course, we're free to manipulate the replacements string as we like. For example, it would be quite valid to have:



I created a file called "program files" just so I could have EXACTLY the same thing being talked about. I copied and pasted ^([A-Z][a-z]*) ([A-Z][a-z]*) into the Match field. The title RegEx(1) immediately turned red. I copied and pasted \2 \1 into the Replace field. Here's what I got.

Image

You will note that the file "program files" has not changed its name to "files program".

I have looked at other RegEx examples in this discussion group. I have copied and pasted several that supposedly work. No matter what, BRU will not recognize any of them and will not rename files using them.

I have reinstalled BRU.

What am I doing wrong?



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

Re: Regular Expressions do not work in my BRU. Period.

Postby hugozam » Thu Jun 26, 2014 12:47 am

Try the following with comma (Linux style):

Code: Select all
^([A-Z,a-z]*) ([A-Z,a-z]*)


or perhaps without comma (I don't know whose style):

Code: Select all
^([A-Za-z]*) ([A-Za-z]*)
hugozam
 
Posts: 5
Joined: Thu Jun 26, 2014 12:40 am

Dont comma-separate ranges within a set

Postby truth » Sat Jun 28, 2014 1:37 am

Hugozam:
BRUs regex wont accept commas as range-separators in a set.
Since - already specs NextChar=EndRange, the comma isnt needed.
Commas are taken literally & become part of the matchable char-set.

This poster wanted to match names beginning with Uppercase,
so Stefan pointed out the flaw in the OrigName created for testing.

I've found myself adding those commas when not needed.
I think some confusion comes from posts with sets like: [0-9,\.]+
where users need to match digits/commas/periods (for #'s like 1,000.00)
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay


Return to Regular Expressions