简体   繁体   中英

substitution and regex perl

Hello I am an amateur to perl and regex

I want to ask the following:

Is it possible to make one substitution argument for the following code:

($inputwoord =~s /[aa|uu|ee|oo]/[a|u|e|o]/) {} 

I basically need to change all dipthongs, so only 1 vowel remains.

However Perl doesn't seem to understand that he must change aa => a oo => o etc ..

He crashes.

Is there a way to correlate the diphtong with the vowel in the same substitution? I don't want to make 4 different substitutions of it...

Thanks!

[...] defines a character class. [aa] is therefore equivalent to [a] .

If you want to search for repeated vowels, you can remember the vowel by a capturing parentheses:

/([aueo])\1/

This matches any character of the class, followed by the same character. To replace it with only one occurrence, use the capturing group again:

s/([aueo])\1/$1/g

So, to change the value of the variable $inputwoord:

$inputwoord =~ s/([aueo])\1/$1/g

BTW, instead of saying He crashes , it's more useful to show the actual error you get. You didn't show enough code for us to be able to guess why Perl crashed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM