#1 2016-09-06 20:09

Stamimail
Member
Registered: 2016-05-08
Posts: 81

How to: ABCX to => ABC"X

ABC = fixed characters
X = variable character ([A-Z])
'' = double '

Last edited by Stamimail (2016-09-06 20:10)

Offline

#2 2016-09-06 22:33

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: How to: ABCX to => ABC"X

Have you tried to use: Insert '' at Position 4?

If that is not what you need, then please provide complete examples.

Offline

#3 2016-09-09 14:13

Stamimail
Member
Registered: 2016-05-08
Posts: 81

Re: How to: ABCX to => ABC"X

ABCX is a word within words in Filename.
In list of Filenames, you can find this word in such cases: ABCA, ABCB, ABCC ... ABCZ
I want to add double apostrophe '' in front of the last letter, like that: ABC''X

Offline

#4 2016-09-09 14:27

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: How to: ABCX to => ABC"X

This can be achieved with the following RegEx rule:

Replace expression "\b(ABC)([\w])\b" with "$1''$2"

Input:

ABCX is a word within words in Filename.
In list of Filenames, you can find this word in such cases: ABCA, ABCB, ABCC ... ABCZ
I want to add double apostrophe '' in front of the last letter, like that: ABC''X

Output:

ABC''X is a word within words in Filename.
In list of Filenames, you can find this word in such cases: ABC''A, ABC''B, ABC''C ... ABC''Z
I want to add double apostrophe '' in front of the last letter, like that: ABC''X

Offline

#5 2016-09-10 23:26

Stamimail
Member
Registered: 2016-05-08
Posts: 81

Re: How to: ABCX to => ABC"X

Is the RegEx works for only English letters?
How to implement this for non-English letters? (the same example above, just the ABCX are non-English letters)

Offline

#6 2016-09-12 10:58

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: How to: ABCX to => ABC"X

RegEx engine does understand Unicode characters which are specified explicitly, but character classes and meta characters such \w and \b currently work only with English character set.

Your task could be achieved with a PascalScript rule, but it will be a bit more complex.

Offline

#7 2016-09-12 11:48

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: How to: ABCX to => ABC"X

den4b wrote:

Your task could be achieved with a PascalScript rule, but it will be a bit more complex.

This is the script that does it, but it will require the next development version of ReNamer (v6.6.0.1 Beta) because it uses newly added functions:

const
  QUOTE = '''''';
var
  Initialized: Boolean;
  ABC: WideString;
  Position: Integer;
begin
  if not Initialized then
  begin
    ABC := WideInputBox('ABC', 'Enter your ABC sequence:', '');
    Initialized := True;
  end;
  if Length(ABC) > 0 then
  begin
    Position := 1;
    while Position > 0 do
    begin
      Position := WideTextPosEx(ABC, FileName, Position);
      if Position > 0 then
      begin
        if Position + Length(ABC) <= Length(FileName) then
        if IsWideCharAlpha(FileName[Position + Length(ABC)]) then
        if IsWideWordBoundaryLeft(FileName, Position) then
        if IsWideWordBoundaryRight(FileName, Position + Length(ABC)) then
        begin
          WideInsert(QUOTE, FileName, Position + Length(ABC));
          Position := Position + Length(QUOTE);
        end;
        Position := Position + Length(ABC);
      end;
    end;
  end;
end.

Offline

Board footer

Powered by FluxBB