Regex not working

Advanced Renamer forum
#1 : 04/06-13 11:21
arwul
arwul
Posts: 88
To find/replace the '-' between characters (note:only... between characters) in a name I use regex:

(?i)(?<=[a-z])-(?=[a-z])
to be replaced by a "space" (ie spacebar)

The regex tester (Regexr) shows this indeed alright and exactly does what I want.

In AR it reports an error 116 (whatever)

Any suggestions?

=


04/06-13 11:21
#2 : 04/06-13 12:06
Kim Jensen
Kim Jensen
Administrator
Posts: 775
Reply to #1:
In Advanced Renamer you cannot use the < or > characters in search pattern. They are reserved for Tags. You will see in the "Error" column that error code 116 means "Invalid tags".


04/06-13 12:06
#3 : 04/06-13 21:50
Stefan
Stefan
Posts: 264
Reply to #1:

Perhaps Kim can in future escape '<' and '>' signs by replace doubled entered sings
to single ones and do not try to parse them as AR tag?
Not sure if ARs regex engine than would support lookaround matching?


- - -

Luckily for the case above you will not need lookaround position matching here.

Simple sign matching is enough:

Text to be replaced: ([a-z])-([a-z])

Replace it with: $1 $2

Occurrences: All

Case Sensitive: checked

Use regular expressions: checked

Apply To: Name



.

----------
If this tool had saved you time, perhaps you want to donate an Dollar to Kim?
See http://www.advancedrenamer.com/download >>> [Donate] button.


04/06-13 21:50
#4 : 06/06-13 13:28
arwul
arwul
Posts: 88
Reply to #3:
Many thanks!
This looks promising.

Any idea if -in the same scenario- I would like to:
find: " - " (space + - + space)
or
find: " -" (space+ -)
or
find: "- " (- +space)
or
find: "_" (underscore)

replace with: space

I tried a lot of combinations but all in vain...

Thanks again
=


06/06-13 13:28
#5 : 06/06-13 15:06
Stefan
Stefan
Posts: 264
Reply to #4:

What do you mean?
Just copy the above shown rule several times
and exchange the hyphen in the expression
with what you want to match now.


Isn't is that what you are after?




.

----------
If this tool had saved you time, perhaps you want to donate an Dollar to Kim?
See http://www.advancedrenamer.com/download >>> [Donate] button.


06/06-13 15:06
#6 : 08/06-13 14:53
arwul
arwul
Posts: 88
Reply to #5:
I was hoping that it could be in 1 line, like:

([a-z]) (( - )|(- )|( -)) ([a-z])

This is NOT corect, but just to get the idea.

--


08/06-13 14:53
#7 : 08/06-13 20:57
Stefan
Stefan
Posts: 264
Reply to #6:

Yes, can be done with one method only too.
You just have to read a regex tutorial.
If you want to write an OR expression try something like this:
([a-z]) - |- | -|-([a-z])


Text to be replaced: ([a-z]) - |- | -|-([a-z])
Replace it with: $1 $2
Occurrences: All
Case Sensitive: checked
Use regular expressions: checked
Apply To: Name

That expression would try to match a lower case char,
followed by " - " OR "- " OR " -" OR "-" {what ever would be found at first},
followed by a lower case char.


- - -


If you would use
([a-z])( - |- | -|-)([a-z])
then you would get three backreference groups and you would have to replace with
$1 $3


On the other hand you could make that second parentheses group a non-capturing group by adding '?:'
([a-z])(?: - |- | -|-)([a-z])
Then that group is not counted and you can replace again by
$1 $2

---

And of course you must not add additional spaces into the expressing like
([a-z]) ( - |- | -|-) ([a-z])
because that would tell to match that blanks too, but they are not existent in your file name.

-

----------
If this tool had saved you time, perhaps you want to donate an Dollar to Kim?
See http://www.advancedrenamer.com/download >>> [Donate] button.


08/06-13 20:57