3
$\begingroup$

I have a list:

lis = {"ab","a-1","1-20"}

from which I need to delete elements of lis that has (only) digits on both sides of the hyphen, in each element that contains a hyphen:

res = {"ab","a-1"}

Thanks In advance for any advice...

$\endgroup$

1 Answer 1

6
$\begingroup$

You can use DeleteCases, Cases, Select, etc. Here a couple of examples:

DeleteCases[lis, s_?StringQ /; StringMatchQ[s, DigitCharacter..~~"-"~~DigitCharacter..]]

Select[lis, !StringMatchQ[#, DigitCharacter..~~"-"~~DigitCharacter..]&]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.