g | x | w | all
Bytes Lang Time Link
052tinylisp 2230112T223640ZDLosc
024Uiua240320T170345Znoodle p
062Swift 5.9240319T194728ZmacOSist
040Lexurgy230112T162402Zbigyihsu
011Vyxal 3240319T185407Zpacman25
036JavaScript220524T085915ZShaggy
015Japt220524T085603ZShaggy
155Nibbles230124T195552ZAdam
048Haskell220531T141512ZWheat Wi
050Haskell220524T174649Zxnor
103Go230112T162728Zbigyihsu
013Vyxal220524T164847ZnaffetS
023V Eh220524T163613Zhdrz
079C gcc with m32220524T195332ZErikF
083StackCell220531T233355ZStarwort
531brainfuck220531T221104Znununois
114GeoGebra220526T000744ZAiden Ch
057Haskell220524T171018ZnaffetS
036Powershell220524T225028Zanother
145Batch220525T005655ZYouserna
113C gcc220524T100443Zmatteo_c
025sed220525T072753ZChris
031APL Dyalog Extended220525T063118Zuser1069
015Pip220524T221334ZDLosc
081C gcc220524T214517Zatt
011Stax220524T185104Zrecursiv
039Lua220524T184013ZLuatic
049SNOBOL4 CSNOBOL4220524T182510ZGiuseppe
045Factor220524T104854Zchunes
029sed220524T140651ZNoodle9
040Java 8220524T111930ZKevin Cr
020Perl 5 + p220524T104559ZDom Hast
025Charcoal220524T103531ZNeil
012Jelly220524T091727ZUnrelate
01305AB1E220524T090137ZKevin Cr
062Python 3.8 prerelease220524T082751ZJitse
053Python220524T091744Zpxeger
149Excel220524T090916ZWernisch
036Zsh220524T082955Zpxeger
019Retina220524T082843Zovs

tinylisp 2, 64 61 52 bytes

(\(S)(: T([(. !(p contains?"aeiou"))S)(? T(,"shm"T)S

Try It Online!

Explanation

Port of Unrelated String's Jelly answer, among others.

First, we need a function that tests whether a character is not a vowel:

(. !(p contains?"aeiou"))
(.                      ) ; Compose
   !                      ; Logical negation
    (p                 )  ; with the partial application of
       contains?          ; the contains? function
                "aeiou"   ; to "aeiou"

Then our main function is as follows (where (...) represents the above function):

(\(S)(: T([(...)S)(? T(,"shm"T)S)))
(\                                ) ; Lambda function
  (S)                               ; that takes a string S:
     (: T                        )  ;  In what follows, let T be
         ([     S)                  ;   Drop characters from S while
           (...)                    ;   they are not vowels
                  (? T          )   ;  Is T truthy (nonempty)?
                      (,"shm"T)     ;  If so, concatenate "shm" with T
                               S    ;  If not, return the original string S

Uiua, 24 bytes

⨬◌(⊂"shm"▽)⊸⊣\↥⊸∊"aeiou"

Try it: Uiua pad

Swift 5.9, 67 63 62 bytes

let f={s in{$0>"" ?"shm"+$0:s}(s.drop{!"aeiou".contains($0)})}

Lexurgy, 42 40 bytes

a:
(!{a,e,i,o,u})*=>shm/$ _ {a,e,i,o,u}

Finds 0 or more not vowels at the start of input before a vowel and replaces them with shm.

Vyxal 3, 11 bytes

Aa[ᶤAİ"=ᵐ„p

Try it Online!

JavaScript, 36 bytes

s=>s.replace(/.*?([aeiou])/,"shm$1")

Try it online! (includes all test cases)

Japt, 15 bytes

r"^.*?%v"ÈÌi`¢m

Try it (Includes all test cases)

r"^.*?%v"ÈÌi`¢m     :Implicit input of string
r                   :Replace
 "^.*?%v"           :  RegEx /^.*?[aeiou]/gi
         È          :  Pass each match through a function
          Ì         :    Last character
           i        :    Prepend
            `¢m     :      Compressed string "shm"

Nibbles, 15.5 bytes

?,;>~$-~?"aeiou"$:"shm"@@

Attempt This Online!

Nibbles has no built-in for vowels, which makes it slightly worse than other golfing languages for this.

Explanation

?         If
,          non-empty
;           x :=
>~           drop-while
$             from input
-~            not
? "aeiou"      contained in "aeiou"
$              it
          then
: "shm"    prepend "shm"
@          to x
          else
@          input

Haskell, 48 bytes

g.break(`elem`"aeiou")
g(s,"")=s
g(_,r)="shm"++r

Try it online!

Haskell, 50 bytes

snd.break(`elem`"aeiou")>>=(?)
""?s=s
r?_="shm"++r

Try it online!

Thanks to Roman Czyborra for -2 bytes

Go, 103 bytes

import."regexp"
func f(s string)string{return MustCompile(`^.*?([aeiou])`).ReplaceAllString(s,"shm$1")}

Attempt This Online!

Vyxal, 13 bytes

k⁰øl:[«88«p|_

Try it Online!

Port of Jelly.

How?

k⁰øl:[«88«p|_
k⁰øl           # Strip leading consonants
    :[         # If there's anything left:
      «88«p    # Prepend "shm"
           |_  # Else, pop, returning the implicit input

V (Eh, vim shmim), 23 bytes

:%s/.\{-}\ze[aeiou]/shm

vim non-greedy regex with look-ahead.

Try it online!

Same in “magic very very” mode:

23 bytes

:%s/\v.{-}[aeiou]@=/shm

Try it online!

Further 3 bytes can be saved by replacing :%s/ with V’s specific í

C (gcc) with -m32, 90 85 83 79 bytes

v;f(char*s){for(v=s;v**s;)index("aeiou",*s++)&&printf("shm",v=0);puts(v?:--s);}

Try it online!

StackCell, 83

(@:{X}X:'a-!?6:'e-!?6:'i-!?6:'o-!?6:'u-!?3!)6"mhs"16:[;:]18(@:!?.;)X{:[{X}X:]X:[;:]

Explanation (for a previous, incomplete version of the program):

(@:'a-!?6:'e-!?6:'i-!?6:'o-!?6:'u-!?2!)"mhs":[;:](@:!?.;) Assumes the input contains a vowel
(                                     )                   Loop over the initial characters, breaking if ) is reached with a non-zero value
 @                                                        Input a character
  :'a-                                                    Duplicate and calculate the difference with the character 'a'
      !?                                                  If there is any difference, skip the next instruction
        6                                                 Skip 6 instructions (to next 6)
         :'e-!?6:'i-!?6:'o-!?6:'u-!?2                     Check the other four vowels; the 2 breaks out of the loop
                                     !                    Negate the character; EOF => 1, anything else => 0
                                       "mhs"              Push the characters mhs to the stack
                                            :[;:]         Print the characters s, h, m, and the vowel that caused the initial loop to break
                                                 (      ) Loop forever (a non-zero value will never be present at the end of the loop
                                                  @:      Input and duplicate a character
                                                    !?.;  If it's non-null (EOF), print it. Otherwise, halt.

brainfuck, 531 bytes

->+[->[>],[+[-<+]->+[>]<[>+>+<<-]>>[<<+>>-]-[>++<-----]>-----<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[[>]<[>+>+<<-]>>[<<+>>-]-[>++<-----]>-<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[[>]<[>+>+<<-]>>[<<+>>-]-[>++<-----]>+++<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[[>]<[>+>+<<-]>>[<<+>>-]-[>--<-------]>+<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[[>]<[>+>+<<-]>>[<<+>>-]----[>+++++<--]>-<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[>]]]]]]+[-<+]->]>[>]<-[++[-<+]->>[.>]>-<]>+[[--------->++<]>+.-----------.+++++.<<<.,[.,]]

Try it online!

This implementation is as close to a nested if/else statement as bf allows. Simply checks each letter to see if it's a vowel. If it finds one, it prints "shm", then the vowel, then the rest of the input. If it doesn't, it simply prints out the input from its buffer.


brainfuck, 423 bytes

+[--------->++<]>+.-----------.+++++.<->>+[>,[>+>+<<-]>>[<<+>>-]-[>++<-----]>-----<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]<<[>[>+>+<<-]>>[<<+>>-]-[>++<-----]>-<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]<<[>[>+>+<<-]>>[<<+>>-]-[>++<-----]>+++<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]<<[>[>+>+<<-]>>[<<+>>-]-[>--<-------]>+<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]<<[>[>+>+<<-]>>[<<+>>-]----[>+++++<--]>-<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]]]]]+[-<+]->>]>.,[.,]

Try it online!

A shorter version that only works for words with vowels.

GeoGebra, 114 bytes

s="a"
InputBox(s)
S=Take(s,IndexOf(Element(Split(s,Split("bcdfghjklmnpqrstvwxyz",{""})),1),s))
If(S=="",s,"shm"+S)

Not sure why, but the code won't work if you put in an empty string as initial value of s (or any string consisting of only consonants), but it will work properly for all test cases (even ones that do consist of only consonants) if you have a string with a vowel as the initial value of s.

The input should be entered into the Input Box.

Try It On GeoGebra!

Haskell, 58 57 bytes

f s|g s>""="shm"++g s|1>0=s
g=dropWhile(`notElem`"aeiou")

Attempt This Online!

-1 byte thanks to Wheat Wizard ♦

Powershell, 36 bytes

$args-replace('^.*?([aeiou])','shm$1')

Explanation

Simple replace with a named group reference.

+4

Thanks caird coinheringaahing

-5

Thanks mazy

Batch, 157 145 bytes

@set i=%1
:l
@(echo %i:~,1%|findstr/r [aeiou]&&set a=1||set a=0)>nul
@if %a%==0 (if %i%. neq . (set i=%i:~1%&goto:l)else echo %1)else echo shm%i%

Input is taken from the command line.

-12 bytes thanks to Neil.

C (gcc), 125 113 bytes

-8 bytes thanks to @ceilingcat

#define T&&*s-
main(s,v)char**v,*s;{for(s=*++v;*s T'a'T'e'T'i'T'o'T'u'||!(*v=memcpy(s-3,"smh",3));++s);puts(*v);}

Try it online!

sed, 25 bytes

/[aeiou]/s/[^aeiou]*/shm/

Try it online!

/[aeiou]/ is a conditional that only runs the substitution s/[^aeiou]*/shm/ if there is a vowel in the line. This prevents needing to capture the first vowel and then using a backreference as in the more obvious s/[^aeiou]*\([aeiou]\)/shm\1/.

APL (Dyalog Extended), 31 bytes

{⍵≢⍛≡n←⌊/⍵⍳'aeoiu':⍵⋄'shm',n↓⍵}

Try it online!

Pip, 15 bytes

a~XVaH$(:"shm"a

Attempt This Online!

Explanation

a~XVaH$(:"shm"a
a                Command-line argument
 ~               Find first match of
  XV             regex `[aeiou]`
      $(         Index of that match
    aH           Prefix of cmdline arg containing that many characters
        :        Set to
         "shm"   that string
                 If a vowel was not found, $( is nil, which means no assignment is done
                 and a's value remains unchanged
              a  Autoprint the (possibly changed) value of a

C (gcc), 81 bytes

i;f(char*s){for(i=0;*s-"aeiou"[++i%6];i%6||s++);printf("shm%s"+3*!*s,s-i*!*s/6);}

Try it online!

Stax, 11 bytes

ÄFï¥░$º{═┘ç

Run and debug it

  1. Left-trim consonants.
  2. If non-empty, prepend "shm".
  3. Else restore original input.

Lua, 39 bytes

print((...):gsub("^.-%f[aeiou]","shm"))

Uses the frontier pattern to shave off two bytes. String must be provided as argument, printed output is (1) the shmodegolfed string and (2) 0 if unmodified, 1 if modified.

Try it online!

SNOBOL4 (CSNOBOL4), 49 bytes

	I =INPUT
	I BREAK('aeiou') ='shm'
	OUTPUT =I
END

Try it online!

BREAK "matches zero or more characters provided they are not in the set of characters in the argument string. That is, it matches up to, but not including, a character from the argument string."

Factor, 70 61 45 bytes

[ R/ ^[^aeiou]*(?=[aeiou])/ "shm"re-replace ]

Try it online!

sed, 29 bytes

s/[^aeiou]*\([aeiou]\)/shm\1/

Try it online!

Java 8, 40 bytes

s->s.replaceAll("^.*?([aeiou])","shm$1")

Port of the JavaScript and Retina answers.

Try it online.

Or a minor alternative:

s->s.replaceAll("^.*?(?=[aeiou])","shm")

Try it online.

Explanation:

s->             // Method with String as both parameter and return-type:
  s.replaceAll( //  Modify and return the String: Regex-replace all
    "...",      //  these matches
    "...")      //  with these replacements

Regex-explanation 1:

^.*?([aeiou])    # Match:
^                #  At the start of the string
 .*              #  Match zero or more characters
   ?             #  Which are optional, to give other matches precedence
     [aeiou]     #  Followed by a vowel
    (       )    #  captured in capture group 1

shm$1            # Replacement:
shm              #  Literal "shm"
   $1            #  And the vowel of capture group 1

Regex-explanation 2:

^.*?([aeiou])    # Match:
^                #  At the start of the string
 .*              #  Match zero or more characters
   ?             #  Which are optional, to give other matches precedence
    (?=       )  #  Followed by a positive (non-matching) look-ahead to:
       [aeiou]   #   A vowel

shm              # Replacement:
shm              #  Literal "shm"

Minor note: the replaceAll with ^ is basically the same as a replaceFirst without the ^, but 1 byte shorter: try it online.

Perl 5 + -p, 20 bytes

Uses the ; separator (as ; is implicitly added via -p).

s;.*?(?=[aeiou]);shm

Try it online!


Perl 5 + -lF/^[^aeiou]+/ -M5.10.0, 17 bytes

Slightly more cheaty with the regex in the flags, but saves a few bytes

say@F?(shm,@F):$_

Try it online!

Charcoal, 25 bytes

≔⌕Eθ№aeiouι¹η¿⊕η«shm✂θη»θ

Try it online! Link is to verbose version of code. Explanation:

≔⌕Eθ№aeiouι¹η

Count the number of vowels in each character and find the first 1 i.e. the index of the first vowel in the input.

¿⊕η

If there was in fact a vowel, then...

«shm✂θη»

... output the literal string shm followed by the input sliced starting at that index.

θ

Otherwise just output the input string.

Jelly, 16 12 bytes

œlØḄṭ⁸¹?“shm

Try it online!

-4 thanks to ovs remembering there's a strip builtin

œlØḄ            Strip all leading consonants.
    ṭ   “shm    Prepend "shm"
      ¹?        if there's anything left, otherwise
     ⁸          give the original word.

05AB1E, 28 13 bytes

žNSÛ©ai®…shmì

Try it online or verify all test cases.

Explanation:

žNSÛ           # Trim all leading consonants of the (implicit) input-string
    ©          # Store this new string in variable `®` (without popping)
     ai        # Pop, and if any letters are left (thus the input-string contains
               # a vowel):
       ®       #  Push string `®` again
        …shmì  #  Prepend "shm"
               #  (implicitly print it as result)
               # (implicit else)
               #  (implicitly output the implicit input-string)

Python 3.8 (pre-release), 62 bytes

lambda s:(q:=s.lstrip('bcdfghjklmnpqrstvwxyz'))and'shm'+q or s

Try it online!

Python, 53 bytes

lambda s:re.sub("^.*?([aeiou])","shm\\1",s)
import re

Attempt This Online!

Another regex answer.


Alternative:

Python, 53 bytes

lambda s:re.sub(".*?(?=[aeiou])","shm",s,1)
import re

Attempt This Online!

Excel, 149 bytes

=IFERROR(REPLACE(A1,1,FIND("$",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"a","$"),"e","$"),"i","$"),"o","$"),"u","$"))-1,"shm"),A1)

102 bytes just to find the vowels. If anybody knows a better way to do this. please share.

From inside out:

Zsh, 36 bytes

<<<${(S)1/#(#b)*([aeiou])/shm$match}

Attempt This Online!

$match is actually an array which contains all the backreference groups, but since there's only one group, we don't need to access any specific element with [1]

Retina, 19 bytes

Just a regex replacement, there might be some language feature which allows for a shorter solution.

^.*?(?=[aeiou])
shm

Try it online!