I have a list. I want to get all the elements in that list which do not match a given pattern. That is, I want the strings which do not match any of the following patterns:
- First and last characters are the same: $123aw1$
- Does not have two consecutive similar characters: $1era22we, awe33rt, 123aa123$
I wrote following code
inputset = ToString /@ {
11223434, 12123434, 11234342, 11234243, 11234234, 11232434, 12132434,
12134234, 11234324, 11232443, 11234423, 12134243, 12314234, 12314324,
12341234, 11223344, 11223443, 11234432
};
outputset = Complement[inputset,
Select[inputset,
StringMatchQ[#, StringExpression[x_, ___, x_]] ||
StringMatchQ[#, StringExpression[___, x_, x_, ___]] &]];
and I got
outputset = {12123434, 12132434, 12134234, 12134243, 12314234, 12314324, 12341234}
Is there an easy simple and efficient way to do this?
Select
with!(PATTERN)
? $\endgroup$Except
? $\endgroup$Except
is pretty limited on string patterns, it only works on one character. You can't use it like:StringMatchQ[{"abc","xyz"}, Except["abc"]]
$\endgroup$