5

I have the following list:

list1 = {"O                    21   B21      20   A20      19   D19      0", \
"90  O            -0.28487   1.23835", "91  O            -0.23761   \
1.29381", "92  O            -0.23093   1.19437", "93  O            \
-0.19657   1.53843", "94  O            -0.17235   1.46275", "O        \
            21   B21      20   A20      19   D19      0", "90  O      \
      -0.28601   1.23805", "91  O            -0.23863   1.29489", "92 \
 O            -0.23206   1.19334", "93  O            -0.19730   \
1.53926"}

I need only the elements that do not have the expression: B21, D19, etc.... Like that:

list1 = { \
"90  O            -0.28487   1.23835", "91  O            -0.23761   \
1.29381", "92  O            -0.23093   1.19437", "93  O            \
-0.19657   1.53843", "94  O            -0.17235   1.46275",  "90  O      \
      -0.28601   1.23805", "91  O            -0.23863   1.29489", "92 \
 O            -0.23206   1.19334", "93  O            -0.19730   \
1.53926"};

So I did:

Cases[%, Except[
  RegularExpression["[A-Z]" ~~ __Integer]], \[Infinity]].

But It did no work.

kglr
  • 394,356
  • 18
  • 477
  • 896
locometro
  • 861
  • 5
  • 14

4 Answers4

5
Select[list1,  StringFreeQ[#, ___ ~~ LetterCharacter ~~ DigitCharacter .. ~~ ___] &]

(*
90  O            -0.28487   1.23835
91  O            -0.23761   1.29381
92  O            -0.23093   1.19437
93  O            -0.19657   1.53843
94  O            -0.17235   1.46275
90  O            -0.28601   1.23805
91  O            -0.23863   1.29489
92  O            -0.23206   1.19334
93  O            -0.19730   1.53926
*)
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
4
Pick[list1, StringFreeQ[#, RegularExpression["[A-Z]\\d"]] & /@ list1] 
Cases[list1, x_?(StringFreeQ[#, RegularExpression["[A-Z]\\d"]] &)]
Select[list1, StringFreeQ[#, RegularExpression["[A-Z]\\d"]] &]
DeleteCases[list1, x_?(!StringFreeQ[#, RegularExpression["[A-Z]\\d"]] &)]

and all of the above with RegularExpression["[A-Z]\\d"] replaced with

Alternatives @@ CharacterRange["A", "Z"] ~~ DigitCharacter

all give

Pick[list1, StringFreeQ[#, RegularExpression["[A-Z]\\d"]] & /@ list1] //Column

enter image description here

where

list1 //Column

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
2

One can also use StringReplace

DeleteCases[StringReplace[list1, x___ ~~ LetterCharacter ~~ NumberString ~~ y___ :> ""], ""]
RunnyKine
  • 33,088
  • 3
  • 109
  • 176
0

I am not sure about this but it looks like (for such specific list) that you can do it like this:

Select[list1, Xnor[StringMatchQ[#, "O" ~~ __]] &]
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78