pm771 wrote:Hi
I'm using BRU 2.7.0.4
Let say we have files names with "-"s in the middle. Something like this:
aaa-bbb
1234--ddd
eee---wwww
We want to remove "-"s using
Regular Expressions (and not the Remove (5) )
The following works:
- Code: Select all
Match: ([^-]*)(-+)(.*)
Replace: \1\3
But the following does
not:
- Code: Select all
Match: (.*)(-+)(.*)
Replace: \1\3
Is it the intended behavior or a bug?
TIA, Eugene
Try
RegEx(1)
Match: (.*)(-+)(.*)
Replace: \1#\3and you see that your regex works greedy.
This means the first "(.+)" eats all till the last dash. That's normal.
Test it
INPUT:Test-1.txt
Test--2Zwei.txt
Test---3Drei.txt
Test----4Vier.txt
OUTPUT:Test#1.txt
Test-#2Zwei.txt
Test--#3Drei.txt
Test---#4Vier.txt
You see that the first (.+) match all but the last dash.
So we try this
RegEx(1)
Match: (.*?)(-+)(.*)
Replace: \1\3or
RegEx(1)
Match: (.*?)-+(.*)
Replace: \1\2and you will see it works as indented:
OUTPUT:Test1.txt
Test2Zwei.txt
Test3Drei.txt
Test4Vier.txt
The "?" switch to non-greedy and so the first expression ".*" stop at the first occurrence of the next expression "-+".
You just have to learn how regex work

An other logically regex would be
RegEx(1)
Match: (.*[^-])(-+)(.*)
Replace: \1\3which means: none-or-more of any sign till an dash
So you has been already on the right track with
Match: ([^-]*)(-+)(.*)
Replace: \1\3
HTH?
