I have some text files in a directory, I want to batch replace:
In each of the file I have the following text, I want to replace the loan in such a way that the last digit in the loan number is incremented by one
For example in the file that contains the loan number 98573745, after the replace it should show loan number incrementing by one
LOAN.NUMBER|98573745
After Replace
LOAN.NUMBER|98573746
Incrementing the string of numbers by one
Go to main menu - Action - Options - Batch Replace
uncheck "Modifier S"
check "Modifier I"
check "Modifier M"
check "Modifier G"
check "Modifier E"
Go to Batch replace tab, check on "Use regular expressions".
Put into the grid, search for:
LOAN\.NUMBER\|(\d+)
Replace with:
LOAN.NUMBER<%=$1+1=%>
That's all I verified it works perfectly.
uncheck "Modifier S"
check "Modifier I"
check "Modifier M"
check "Modifier G"
check "Modifier E"
Go to Batch replace tab, check on "Use regular expressions".
Put into the grid, search for:
LOAN\.NUMBER\|(\d+)
Replace with:
LOAN.NUMBER<%=$1+1=%>
That's all I verified it works perfectly.
Additional Similar Batch Replace
Batch replacment for Loan.Number|12345678
Worked. Here is additional Batch replacement I am doing.
Let me know if this looks correct.
for
LOAN.PREAPP-NUMBER|901998412
I am using
LOAN.PREAPP-NUMBER<%=$1+1=%>
but somehow when I did it, my xml file got corrupted, I could not open them.
I would like to attach my xml file, is there a way I can do it?
Worked. Here is additional Batch replacement I am doing.
Let me know if this looks correct.
for
LOAN.PREAPP-NUMBER|901998412
I am using
LOAN.PREAPP-NUMBER<%=$1+1=%>
but somehow when I did it, my xml file got corrupted, I could not open them.
I would like to attach my xml file, is there a way I can do it?
One remark:
For your first example the correct Replace With expression should be:
LOAN.NUMBER|<%=$1+1=%>
In fact I forgot to put | char after NUMBER
for your second example, the correct pair is:
search for
LOAN\.PREAPP-NUMBER\|(\d+)
replace with:
LOAN.PREAPP-NUMBER|<%=$1+1=%>
So . (dot) and | are reserved chars and you should escape it with \
I think your XML files were corrupted due to incorrect regular
expressions.
Another think could be:
You should activate using Unicode.
Go to main menu - Action - Options - Advanced:
check "Handle Unicode Files" option.
For your first example the correct Replace With expression should be:
LOAN.NUMBER|<%=$1+1=%>
In fact I forgot to put | char after NUMBER
for your second example, the correct pair is:
search for
LOAN\.PREAPP-NUMBER\|(\d+)
replace with:
LOAN.PREAPP-NUMBER|<%=$1+1=%>
So . (dot) and | are reserved chars and you should escape it with \
I think your XML files were corrupted due to incorrect regular
expressions.
Another think could be:
You should activate using Unicode.
Go to main menu - Action - Options - Advanced:
check "Handle Unicode Files" option.
For this case you should use:
Search for:
LOAN\.PREAPP-NUMBER\|R(\d+)
Replace with:
LOAN.PREAPP-NUMBER|R<%=$1+1=%>
Explanations:
as I already said . and | are reserved chars. So we escape these chars
with \. This escaping is only used for Search For part.
\d means any digit (Read the Syntax of regular expressions).
We use \d+ because we need it to match one or more digits (It's noted
in the Syntax of regular expressions too).
(\d+) is used because we want to put \d+ into parameter $1 which will be
used later in Replace With part.
Now in Replace with part we use <%= =%> because we need to evaluate
some expressions.
What is inside <%= =%>? Inside we have $1+1. In fact we take the parameter
$1 and increment it by 1. What is $1 parameter? As it's stated above:
$1 is \d+ which means any one or more digits (an integer number).
That's all. I hope now it will be more clear about how regular
expressions work.
Search for:
LOAN\.PREAPP-NUMBER\|R(\d+)
Replace with:
LOAN.PREAPP-NUMBER|R<%=$1+1=%>
Explanations:
as I already said . and | are reserved chars. So we escape these chars
with \. This escaping is only used for Search For part.
\d means any digit (Read the Syntax of regular expressions).
We use \d+ because we need it to match one or more digits (It's noted
in the Syntax of regular expressions too).
(\d+) is used because we want to put \d+ into parameter $1 which will be
used later in Replace With part.
Now in Replace with part we use <%= =%> because we need to evaluate
some expressions.
What is inside <%= =%>? Inside we have $1+1. In fact we take the parameter
$1 and increment it by 1. What is $1 parameter? As it's stated above:
$1 is \d+ which means any one or more digits (an integer number).
That's all. I hope now it will be more clear about how regular
expressions work.