I only need to find all 3-digit numbers containing 1 2 and 3 digits
Then you can use safely
grep('^[123]{3}$', a, value=TRUE)
##=> [1] "112" "123" "113" "212" "223" "213" "312" "323" "313"
The regular expression matches:
^
- beginning of line[123]{3}
- Exactly 3 characters that are either 1
, or 2
or3
$
- approve the position at the end of the line.
, , unique
.
, Perl:
grep('^(?!.*(.).*\\1)[123]{3}$', a, value=TRUE, perl=T)
## => [1] "123" "213" "312"
. (?!.*(.).*\\1)
, (.)
, . , . IDEONE.
(?!.*(.).*\\1)
. - regex, true, , false. , "" , "" , . (^
). , regex .*
( , , 0 ), 1 (.)
1, 0 .*
, 1 \\1
. , 121
, , look-forward false, 1
s.