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.


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.


""                              =>   ""
"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.

  • 2
    \$\begingroup\$ I'm not sure if anyone has welcomed you to the stack yet, so: welcome to Code Golf Stack Exchange! Nicely specified first challenge. :-) \$\endgroup\$
    – Giuseppe
    Commented Aug 14, 2019 at 15:05
  • \$\begingroup\$ @Giuseppe Thanks for the kind words! \$\endgroup\$ Commented Aug 16, 2019 at 8:21
  • \$\begingroup\$ Also in Spanish es.wikipedia.org/wiki/Jerigonza \$\endgroup\$
    – leonbloy
    Commented Aug 16, 2019 at 15:12

12 Answers 12


JavaScript (ES6), 35 bytes


Try it online!

Where the special replacement pattern $& means matched substring.

  • 8
    \$\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
    Commented Aug 13, 2019 at 22:50
  • 2
    \$\begingroup\$ Is $& the more common way? In Java it's $0 a.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\$ Commented Aug 14, 2019 at 6:37

Sed, 30, 25, 21, 19 Bytes

-5 Bytes Thanks to Arnauld!
-4 Bytes Thanks to Shaggy!
-2 Bytes Thanks to Leo Tenenbaum!


Try it Online!


Japt, 10 bytes


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\$
    – Gymhgy
    Commented Aug 13, 2019 at 21:39
  • \$\begingroup\$ @EmbodimentofIgnorance, you'd need \y instead of \v. \$\endgroup\$
    – Shaggy
    Commented Aug 13, 2019 at 22:44

Java 8, 40 bytes


Try it online.


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

Perl 5 -p, 20 bytes


Try it online!


Python 3, 55 bytes

lambda s:re.sub('([aeiouy]+)',r'\1p\1',s,0,2)
import re

Try it online!

Sans regex:

Python 3, 101 bytes

def f(s,q=''):i=s[:1];t=i in{*'aeiouyAEIOUY'};return(q+(q!='')*'p'+q+i)*0**t+(s and f(s[1:],(q+i)*t))

Try it online!

Python 3.8 (pre-release): 99 bytes


Recursive function, accepting a string s and an optional argument q. If the first character of s (i) is a vowel, it is stored in the queue q. If not, a string is returned which is composed of q, the letter 'p', q again, the character i and the result of the recursive function with the first character of the string stripped off. Recursion stops when the function encounters an empty string s.

  • 2
    \$\begingroup\$ Love the solution without regex! \$\endgroup\$ Commented Aug 14, 2019 at 10:34

05AB1E, 22 20 bytes


05AB1E doesn't have any regexes unfortunately.
I don't really like the duplicated žÁyнå, but I'm currently a bit too busy to look for alternatives..

-2 bytes thanks to @Grimy for showing me a constant I didn't even knew existed (and was missing from the Wiki page.. >.>)

Try it online or verify all test cases.


.γ               # Group the characters in the (implicit) input-string by:
  žÁ             #  Push vowels builtin: "aeiouyAEIOUY"
    yå           #  And check if the current character is in this string
 }v              # After grouping: loop over each group `y`:
   y             #  Push group `y`
    žÁyнåi   }   #  If the first character of the group is a vowel:
          'p    '#   Push a "p"
            y    #   And push group `y` again
              J  #  Join everything on the stack together to a single string
                 # (after the loop, implicitly output the result)
  • \$\begingroup\$ žÁ instead of žO lets you drop the l. \$\endgroup\$
    – Grimmy
    Commented Aug 14, 2019 at 12:09
  • \$\begingroup\$ @Grimy Maybe I should start using the info.txt file instead of the Wiki page.. -_-' \$\endgroup\$ Commented Aug 14, 2019 at 12:29
  • \$\begingroup\$ They're both missing lots of commands, though not the same ones (hopefully. Sometimes I wonder if there are secret commands missing from both). \$\endgroup\$
    – Grimmy
    Commented Aug 14, 2019 at 12:31
  • 1
    \$\begingroup\$ @Grimy Yeah, maybe we should use the source code instead of the info.txt or Wiki pages. ;) \$\endgroup\$ Commented Aug 14, 2019 at 12:32

Retina 0.8.2, 17 bytes


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


Try it online!


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 course Red's Parse is much more verbose than regex.

  • 1
    \$\begingroup\$ More verbose than regex for sure, but perhaps that makes it more interesting as well. I like it! \$\endgroup\$ Commented Aug 14, 2019 at 9:07
  • \$\begingroup\$ @MaartenBamelis Thank you! Yes, Red (like Rebol) is an interesting language. \$\endgroup\$ Commented Aug 14, 2019 at 9:16

SNOBOL4 (CSNOBOL4), 97 bytes

S	I ARB . L SPAN('AEIOUYaeiouy') . V REM . I	:F(O)
	O =O L V 'p' V	:(S)

Try it online!

Vowel clusters match SPAN('AEIOUYaeiouy').


Stax, 17 bytes


Run and debug it at staxlang.xyz!

Unpacked (20 bytes) and explanation:

                   R    Regex replace using
Vv'y+                     Push "aeiou", push "y", and concatenate
     c^+                  Copy, convert copy to all caps, and concatenate
        :}                Enclose in []
          '++             Push "+" and concatenate
                        And replacement:
             {    }       Block:
              'p            Push "p"
                n           Copy second item (matching substring) to top
                 L          Listify
                          Implicit concatenate
                        Implicit print

No case-insensitive regular expressions in Stax, and the vowel builtins don't include Y. The documentation won't tell you about using a block as a replacement, but it's a working feature nevertheless.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.