Lípínguapua dopo PêpêaR
Língua do Pê, or P Language, is a language game spoken in Brazil and Portugal with Portuguese. It is also known in other languages, such as Dutch and Afrikaans. (Wikipedia)
There are some dialects in this language game. The different languages the game is played with even have their own unique dialects. Some people are fluent in speaking P Language and the best can even translate any text to their preferred dialect on the spot!
P Language
In this challenge, we will use the Double Talk dialect.
To translate text into P Language, any sequence of vowels in the text is appended with a single p character followed by a copy of the sequence of vowels.
Challenge
Write a function or program that accepts a string as input and outputs its translation in P Language.
- The input consists only of printable ASCII characters.
- The output consists only of the translated input and optionally a trailing newline.
- Vowels are any of the following characters
aeiouyAEIOUY. - A sequence of vowels is delimited by any other character. The string
"Aa aa-aa"has three vowel sequences. - Leading and trailing whitespace may optionally be omitted from the translated output string.
Examples
"" => ""
"Lingua do Pe" => "Lipinguapua dopo Pepe"
"Hello world!" => "Hepellopo woporld!"
"Aa aa-aa" => "AapAa aapaa-aapaa"
"This should be easy, right?" => "Thipis shoupould bepe eapeasypy, ripight?"
"WHAT ABOUT CAPS?" => "WHApAT ApABOUpOUT CApAPS?"
" Hi " => " Hipi " or "Hipi"
The double quotes character " is used to delimit the input and output strings in the examples but obviously this character may also appear in any valid input string.
9 Answers
Japt, 10 bytes
r"%y+"_+ip
Try it
r"%y+"_+ip :Implicit input of string
r :Replace
"%y+" :RegEx /[aeiouy]+/gi
_ :Pass each match through a function
+ : Append a copy of the match
ip : Prepended with "p"
-
\\$\\begingroup\\$ Darn it, 2 minutes too late! I had the exact same answer, except it used Japt 2.0 short regexes
"%v"->\\v\\$\\endgroup\\$ – Embodiment of Ignorance 10 hours ago -
\\$\\begingroup\\$ @EmbodimentofIgnorance, you'd need
\\yinstead of\\v. \\$\\endgroup\\$ – Shaggy 9 hours ago
JavaScript (ES6), 35 bytes
s=>s.replace(/[aeiouy]+/gi,'$&p$&')
Try it online!
Where the special replacement pattern $& means matched substring.
-
4\\$\\begingroup\\$ I did not know about
$&. All these years, I've been wrapping the whole regex in a capture group. Who said code golf is impractical?! \\$\\endgroup\\$ – recursive 9 hours ago -
\\$\\begingroup\\$ Is
$&the more common way? In Java it's$0a.f.a.i.k., and Retina allows both. Didn't knew$&came from JavaScript. Or is it a .NET flavored regex, and JavaScript also uses it? \\$\\endgroup\\$ – Kevin Cruijssen 1 hour ago
Sed, 30, 25, 21, 19 Bytes
-5 Bytes Thanks to Arnauld!
-4 Bytes Thanks to Shaggy!
-2 Bytes Thanks to Leo Tenenbaum!
s/[aeiouy]\\+/&p&/gi
Try it Online!
-
\\$\\begingroup\\$ It doesn't look like you need the parentheses within your RegEx. \\$\\endgroup\\$ – Shaggy 9 hours ago
-
\\$\\begingroup\\$ 19 bytes: tio.run/##BcGxCsIwEAbg/Z7id@mikkco0SWDYMEUB3U4yZEcBCONofTp4/… \\$\\endgroup\\$ – Leo Tenenbaum 6 hours ago
Retina 0.8.2, 17 bytes
i`[aeiouy]+
$&p$&
Try it online! Link includes test cases. Explanation: Trivial regexp approach; the i flag turns on case insensitivity (Retina already defaults to a global match).
Jelly, 20 bytes
Żṁe€ØyŒg$$,j”pƊ€ÐeẎḊ
Try it online!
Perl 5 -p, 20 bytes
s/[aeiouy]+/$&p$&/gi
Try it online!
Java 8, 40 bytes
s->s.replaceAll("(?i)[aeiouy]+","$0p$0")
Try it online.
Explanation:
s-> // Method with String as both parameter and return-type
s.replaceAll("(?i)[aeiouy]+", // Replace the regex matches
"$0p$0") // With this replacement
Regex explanation:
(?i)[aeiouy]+ // MATCH:
(?i) // Enable case insensitivity
+ // Match one or more
[aeiouy] // Adjacent vowel characters
$0p$0 // REPLACEMENT:
$0 // The entire match (the vowel 'sequence')
p // Appended with a literal "p"
$0 // Appended with the entire match again
Red, 92 bytes
func[s][v: charset"aeiouyAEIOUY"parse s[any[to v copy t any v insert(rejoin["p"t])| skip]]s]
Try it online!
Of coure Red's Parse is much more verbose than regex.
Python 3, 127 bytes
def f(s,q=''):
if s and s[0]in'aeiouyAEIOUY':n='';q+=s[0]
else:n=(q!='')*(q+'p'+q)+s[:1];q=''
return n+f(s[1:],q)if s else n
Try it online!