S
S
streetn12017-11-23 08:30:15
Perl
streetn1, 2017-11-23 08:30:15

How to find all words in a text with two vowels using a regular expression?

Given any text, you need to find all words with two vowels.
I tried to do it myself, but I can not understand where to start?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
krypt3r, 2017-11-23
@krypt3r

#!/usr/bin/perl

use strict;
use warnings;
use utf8;
use open qw/:std :utf8/;

my $text = "Как найти слова с двумя гласными?";
my @words = split /\s+/, $text;
my ($count, @result, $tmp_word);
for my $word (@words) {
    $tmp_word = $word;
    $count = ($word =~ s/[уеёыаоэяию]//g);
    push @result, $tmp_word if $count == 2;
}

for (@result) {
    print $_, "\n";
}

K
KazeZlat, 2017-11-23
@KazeZlat

With two definite vowels, or containing 2 vowels?
Regex101 is a great testing tool, paste your text there and experiment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question