Tom Erdos
Tom Erdos

Reputation: 111

Delete unique term from array with regex

Suppose I have an array

@arr = qw( 12 2 5 bba<1s54> 10 11 )

How I can delete non-numeric items from this array, in this case "bba<1s54>"?

This unique "term" has format "bba<...>". Is it possible to use regex to delete it?

Upvotes: 0

Views: 110

Answers (1)

TLP
TLP

Reputation: 67900

You can grep the result for numbers only:

my @arr = qw(12 2 5 bba<1s54> 10 11);
@arr = grep /^\pN+$/, @arr;

If you know exactly what to remove, it is stricter to just remove that. E.g.:

@arr = grep !/bba<.*>/, @arr;

Upvotes: 6

Related Questions