comb
in Perl 6 is like a complement of split
. Instead of choosing what to exclude from the results, you are choosing what to include. Is there a Python equivalent, and if so, what is it?
So far, all of my searching for "Python comb" gives me results related to "combinations", not "the complement of split".
Here is an example of it in Perl 6:
#!/bin/env perl6
my $text = "5 foos, 16 bars, 7 bazes";
my @result = $text.comb(/\d+/); # \d matches numbers
say @result.join(" "); # 5 16 7
Update based on feedback: comb
is more like a complement of split
than its "opposite".
str.join
? – Rakesh Apr 26 '18 at 17:30re.findall()
, which finds all the matches of a regular expression. – Barmar Apr 26 '18 at 17:32((?:pattern)+)
– Barmar Apr 27 '18 at 19:50