public class SubstitutionTest extends Object
| Constructor | Description |
|---|---|
SubstitutionTest() |
| Modifier and Type | Method | Description |
|---|---|---|
void |
testNameSubstitutionRegex() |
The nameSubstitution regex:
|
void |
testNumberSubstitutionRegex() |
The numberSubstitution regex:
|
public void testNumberSubstitutionRegex()
The numberSubstitution regex:
$number
In this example we define the following match pattern:
\b(\w+)(\s)(\w+)\b
And the following substitution pattern:
$3$2$1
Using the String "one two" as input the following will happen:
"one" will be matched as the first group;
" " will be matched as the second group;
"two" will be matched as the third group;
Or:
$1 $2 $3
"one" " " "two"
Since the substitution pattern is "$3$2$1" the words will be rearranged and will generate the following String:
$3 $2 $1
"two" " " "one"
public void testNameSubstitutionRegex()
The nameSubstitution regex:
${name}
In this example we define the following match pattern:
\b(?<word1>\w+)(\s)(?<word2>\w+)\b
And the following substitution pattern:
${word2} ${word1}
Using the String "one two" as input the following will happen:
"one" will be matched as the group word1;
" " will be matched as the second group;
"two" will be matched as the group word2;
Or:
word1 $2 word2
"one" " " "two"
Since the substitution pattern is "${word2} ${word1}" the words will be rearranged and will generate the following String:
word2 " " word1
"two" " " "one"
Copyright © 2018. All rights reserved.