[Question]
  [
Ever fancied creating cool twitter hashtags such as *#brexit* or *#brangelina*? this golf is for you.
---
Write a program that accepts two strings A & B as input and merges them according to the following algorithm:
1. let `n` be the number of vowels groups in A (e.g. `britain` has 2 vowels groups : `i` in position 3 and `ai` in position 5).
	* if n = 1 : truncate A starting at its first vowel group position (example: `bill` => `b`)
	* if n > 1 : truncate A starting at its `n-1`th vowel group position (example: `programming` => `progr`, `britain` => `br`)
2. remove all consonants at the beginning of B (`jennifer` =>
`ennifer`)
3. concatenate the modified A & B
Vowels are `aeiou`; consonants are `bcdfghjklmnpqrstvwxyz`.
## Input
You can assume the input strings are lowercase and contain at least one vowel and one consonant.
## Examples
```
brad + angelina      => brangelina
britain + exit       => brexit
ben + jennifer       => bennifer
brangelina + exit    => brangelexit
bill + hillary       => billary
angelina + brad      => angelad
programming + puzzle => progruzzle
code + golf          => colf
out + go             => o
```
  
[Answer]
# Ruby, ~~44~~ ~~43~~ 40 + 1 = 41 bytes
+1 byte for `-p` flag. Takes space-separated input on STDIN.  
-1 byte thanks to Martin Ender  
-2 bytes thanks to histocrat
```
sub /([aeiou]+([^aeiou]*)){,2} \g<2>/,""
```
[Try it online!](https://tio.run/##PYzLCsIwEEX3@Yqhq1YrBdfij1SFiZ3GkXQS0gRsxV83VnxsLgfO4Yakp5zHpKEpWyR26bgu29OHVlV1r7cPOJjddt/URZGzDtgBiiHLgkoHjsgCdOOoNAlcSYR7Cov5RV/J1sJlGQyT@qv3m/LBmYDDwGLAp3m2BOrsOgLjbK9cigs8nY/sZMwb/wI "Ruby – Try It Online")
## GNU sed, ~~39~~ 37 + 1 = 38 bytes
+1 byte for `-E` flag. Takes space-separated input on STDIN.  
-1 byte thanks to Martin Ender
```
s/([aeiou]+[^aeiou]*){,2} [^aeiou]*//
```
[Try it online!](http://sed.tryitonline.net/#code=cy8oW2FlaW91XStbXmFlaW91XSopeywyfSBbXmFlaW91XSovLw&input=YnJhZCBhbmdlbGluYQpicml0YWluIGV4aXQKYmVuIGplbm5pZmVyCmJyYW5nZWxpbmEgZXhpdApiaWxsIGhpbGxhcnkKYW5nZWxpbmEgYnJhZApwcm9ncmFtbWluZyBwdXp6bGUgCmNvZGUgZ29sZgpvdXQgZ28&args=LUU)
Not posting this as a separate answer because it is literally the same solution.
[Answer]
# MATL, ~~31~~ 30 bytes
```
t13Y2XJmFwhdl=fql_):)itJmYsg)h
```
[**Try it Online**](http://matl.tryitonline.net/#code=dDEzWTJYSm1Gd2hkbD1mcWxfKTopaXRKbVlzZylo&input=J3Byb2dyYW1taW5nJwoncHV6emxlJw)
**Explanation**
```
t       % Implicitly grab the input and duplicate it
13Y2    % Push the string literal 'aeiouAEIOU'
XJ      % Store this in clipboard J for later use
m       % Check which characters from the input are vowels (true for vowel)
Fwh     % Prepend FALSE to this logical array
dl=     % Compute the difference and find where we went from not-vowel to vowel
f       % Find the indices of these transitions
q       % Subtract 1 to get the location of the last consonant in each transition
l_)     % Get the next-to-last one of these
:)      % Grab the first string up to this location
% Now for the second component!
it      % Explicitly grab the input and duplicate
J       % Retrieve the string literal 'aeiouAEIOU' from clipboard J
m       % Find where the vowels are (true for vowel)
Ys      % Compute the cumulative sum along the array. The result will be 0
        % for all characters before the first vowel and non-zero after
g)      % Convert to logical and use this as an index so any characters
        % after the first value are retrieved
% Now to combine them
h       % Horizontally concatenate the first and second pieces together
        % Implicitly display the result
```
[Answer]
# JavaScript (ES6), ~~81~~ ~~73~~ 72 bytes
*Saved 8 bytes thanks to @Jordan, 1 thanks to @DavidConrad*
```
a=>b=>a.match(/.*?(?=(?:[aeiou]+[^aeiou]*){1,2}$)/)+b.match(/[aeiou].*/)
```
Even though `.match` returns an array, `array+array` returns a string with the contents of the arrays concatenated (i.e. `[0]+[1]` returns `"01"`).
### Test snippet
```
f=a=>b=>console.log(a,"+",b,"=",a.match(/.*?(?=(?:[aeiou]+[^aeiou]*){1,2}$)/)+b.match(/[aeiou].*/))
f("brad")("angelina")
f("britain")("exit")
f("ben")("jennifer")
f("brangelina")("exit")
f("bill")("hillary")
f("angelina")("brad")
f("programming")("puzzle")
f("code")("golf")
f("progruzzle")("colf")
f("out")("go")
```
```
<input id=A value="super">
<input id=B value="chafouin">
<button onclick="f(A.value)(B.value)">Run</button>
```
Jordan's excellent Ruby solution would be 53 bytes in JS:
```
x=>x.replace(/([aeiou]+[^aeiou]*){1,2} [^aeiou]*/,"")
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~23~~ 22 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
e€ØcT
Çµḟ‘-ị’
Ç⁸ḣ⁹ÑḢ⁹ṫ
```
**[TryItOnline](http://jelly.tryitonline.net/#code=ZeKCrMOYY1QKw4fCteG4n-KAmC3hu4vigJkKw4figbjhuKPigbnDkeG4ouKBueG5qw&input=&args=InByb2dyYW1taW5nIg+InB1enpsZSI)**
How?
```
e€ØcT    - Link 1, vowel indexes: s   e.g. "colouring"
  Øc     - yield vowels, "AEIOUaeiou"
e€       - in for each                     [0,1,0,1,1,0,1,0,0]
    T    - truthy indexes (1-based)        [2,4,5,7]
Çµḟ‘-ị’  - Link 2, n-1th or only vowel group index start - 1: s
 µ       - monadic chain separation
Ç        - call last link (1) as a monad   [2,4,5,7]
   ‘     - increment                       [3,5,6,8]
  ḟ      - filter out                      [2,4,7]
    -    - -1
     ị   - index value                     [4]
               (Jelly is 1-based and has modular indexing,
                so the last but one item is at index -1,
                and when there is only 1 item in the list it is also at index -1)
      ’  - decrement                       [3]
Ç⁸ḣ⁹ÑḢ⁹ṫ - Main link: a, b                      e.g. "colouring", "pencils"
Ç        - call last link (2) as a monad with a      [3]
 ⁸       - link's left argument, a
  ḣ      - head a[:y]                                "col"
   ⁹  ⁹  - link's right argument, b
    Ñ    - call next link (1) as a monad                          [2,5]
     Ḣ   - pop head                                               [2]
       ṫ - tail b[y-1:]                                           "encils"
         - implicit print                            "colencils"
```
[Answer]
## PowerShell v2+, 76 bytes
```
param($n,$m)($n-replace'([aeiou]+[^aeiou]*){1,2}$')+($m-replace'^[^aeiou]*')
```
Apparently this is a popular regex ... ;-)
Uses the `-replace` operator to pull off the appropriate pieces, then string-concatenates the results together. Adds on a `$` to the first to ensure we pull the end of the string, and adds a `^` to the second to ensure we pull off the front of the string.
[Answer]
## [Retina](http://github.com/mbuettner/retina), 35 bytes
```
([aeiou]+[^aeiou]*){1,2} [^aeiou]*
```
[Try it online!](http://retina.tryitonline.net/#code=JShHYAooW2FlaW91XStbXmFlaW91XSopezEsMn0gW15hZWlvdV0qCg&input=YnJhZCBhbmdlbGluYQpicml0YWluIGV4aXQKYmVuIGplbm5pZmVyCmJyYW5nZWxpbmEgZXhpdApiaWxsIGhpbGxhcnkKYW5nZWxpbmEgYnJhZApwcm9ncmFtbWluZyBwdXp6bGUKY29kZSBnb2xmCm91dCBnbw) (The first line enables a linefeed-separated test suite.)
Simply removes all matches of the regex on the first line.
[Answer]
# Cinnamon Gum, 23 bytes
```
0000000: 64d3 884e 4ccd cc2f 8dd5 8e8e 8330 b434  d..NL../.....0.4
0000010: b108 d92b c0d9 00                        ...+...
```
[Try it online.](http://cinnamon-gum.tryitonline.net/#code=MDAwMDAwMDogNjRkMyA4ODRlIDRjY2QgY2MyZiA4ZGQ1IDhlOGUgODMzMCBiNDM0ICBkLi5OTC4uLy4uLi4uMC40CjAwMDAwMTA6IGIxMDggZDkyYiBjMGQ5IDAwICAgICAgICAgICAgICAgICAgICAgICAgLi4uKy4uLg&input=YnJpdGFpbiBleGl0)
## Explanation
This decompresses to `d([aeiou]+[^aeiou]*)([aeiou]+[^aeiou]*)? [^aeiou]*`, which `d`eletes anything matching that regex. (Note that Jordan's golfier `d([aeiou]+[^aeiou]*){,2} [^aeiou]*` compresses to 24 bytes due to the lack of repeated elements to compress.)
[Answer]
# PHP, 95 Bytes
```
$t="aeiou]";echo($p=preg_filter)("#([$t+[^$t*){1,2}$#","",$argv[1]).$p("#^[^$t*#","",$argv[2]);
```
with preg\_match instead of preg\_filter 110 Bytes
```
$t="aeiou]";($p=preg_match)("#(.*?)([$t+[^$t*){1,2}$#",$argv[1],$m);$p("#[$t.*#",$argv[2],$n);echo$m[1].$n[0];
```
[Answer]
## Lua, 66 bytes
```
$ cat merge.lua
print(((...):gsub(("[]+[^]*[]*[^]*+[^]*"):gsub("]","aeiou]"),"")))
$ lua merge.lua brad+angelina
brangelina
$ lua merge.lua programming+puzzle
progruzzle
```
[Answer]
# Perl 5, 39 bytes
38, plus 1 for `-pe` instead of `-e`
```
s/([aeiou]+[^aeiou]*){1,2} [^aeiou]*//
```
[Hat tip.](/a/94538)
[Answer]
# Python 2, 139 bytes
```
n=lambda a,b:a[:a.index(([l for l in[[l,"!"][i!=0and a[i-1]in v]for i,l in enumerate(a)]if l in v]*2)[-2])]+b[sorted([(b+v).index(c)for c in v])[0]:]
```
This one was hard.
[Check it out on repl.it](https://repl.it/DiK6/40)
[Answer]
# [Lithp](https://github.com/andrakis/node-lithp), 65 bytes
```
#X::((replace X (regex "([aeiou]+[^aeiou]*){1,2} [^aeiou]*") ""))
```
---
This is basically a port of the JavaScript answer above, in my Lisp-ish functional programming language.
Example usage:
```
(
    % Note, you can define this as a function, or assign it to a variable
    % and use the call function instead.
    (def f #X::((replace X (regex "([aeiou]+[^aeiou]*){1,2} [^aeiou]*") "")))
    (print (f "programming puzzle"))
)
```
No online interpreter yet. I'll provide one soon. It won't be difficult, my language is written in JavaScript.
Instead, this puzzle solution is implemented as a working example for my language. It can be run with the following command:
```
node run.js l_src/progruzzle-colf.lithp
```
[Answer]
# Haskell, ~~111~~ 108 bytes
```
v x=elem x"aeiou"
d=dropWhile
e=d v
k=d$not.v
r=reverse
f a|c<-e.k.e.k$a,""/=c=c|1<3=e.k$a
a!b=(r.f.r)a++k b
```
This non-regex solution turned out longer than expected. [Ideone it anyway.](https://ideone.com/REZWtG)
[Answer]
# [Jq 1.5](https://stedolan.github.io/jq/), 45 bytes
```
gsub("([aeiou]+[^aeiou]*){1,2} [^aeiou]*";"")
```
Nothing special, just a port of [msh210](https://codegolf.stackexchange.com/users/1976/msh210)'s perl solution to jq's PCRE.
[Try it online!](https://tio.run/##VY7LbsIwEEX3fMXI3fDKomwR/EhEpYEYM8iMg7HVlsKv19hhEoEXlu@5R1c@nhOUo7YeG0A22hKjgg9YrSEzAaOszItEAYlB/1AYnBL6XjMcNTPtte97icNCP/k@0tHXJbIWDvlC/9tLzyTCMFM@LkbHsBGj9c54PJ2IDbTxerVatK7ogJg712gwzu5F2OWnVC6G3Ah3Bd6SucTtWI1r1OTiZlZ/PR/Tyd/nfHGHIaulUpOU/l0byPElVRVHayviNoYcPH5XeT6HBw "jq – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 18 bytes
```
r/\v+\V*){1,2} \V*
```
[Try it online!](https://ethproductions.github.io/japt/?v=2.0a0&code=ci9cditcViopezEsMn0gXFYq&input=LW1SIFsKImJyYWQgYW5nZWxpbmEiLAoiYnJpdGFpbiBleGl0IiwKImJlbiBqZW5uaWZlciIsCiJicmFuZ2VsaW5hIGV4aXQiLAoiYmlsbCBoaWxsYXJ5IiwKImFuZ2VsaW5hIGJyYWQiLAoicHJvZ3JhbW1pbmcgcHV6emxlIiwKImNvZGUgZ29sZiIsCiJvdXQgZ28iCl0=)
Direct port of [short JS solution](https://codegolf.stackexchange.com/a/94536/78410) which is in turn the port of [Jordan's Ruby solution](https://codegolf.stackexchange.com/a/94538/78410).
### How it works
```
Ur/\v+\V*){1,2} \V*/
Ur    Replace on the input...
/\v+\V*){1,2} \V*/  this regex with empty string.
      \v == [AEIOUaeiou], \V == [^AEIOUaeiou], `g` flag is on by default in Japt
      so the uncompressed regex is roughly /([aeiou]+[^aeiou]*){1,2} [^aeiou]*/g.
```
]