I use "suffix" loosely here to mean "any sub-string that follows the prefix".
"Prefix" here means the START of a word, where a word's start is defined as either after a space or from the first character of the input text (for the first word). A "prefix" in the middle of a word is ignored.
E.g. if your input prefix is "arm" and the input text is "Dumbledore's army was fully armed for the impending armageddon" then the output list contains (y, ed, ageddon).
Test Cases
Assume case-sensitive, strings end after spaces. Input will not start with a space.
Removing duplicates is optional.
Input prefix: "1"
Input text:
"He1in aosl 1ll j21j 1lj2j 1lj2 1ll l1j2i"
Output: (ll, lj2j, lj2) - in any permutation
Input prefix: "frac"
Input text:
"fracking fractals fracted fractional currency fractionally fractioned into fractious fractostratic fractures causing quite a fracas"
Output: (king, tals, ted, tional, tionally, tioned, tious, tostratic, tures, as)
Input prefix: "href="https://www.astrotheme.com/astrology/"
Input text:
"(div style="padding: 0; background: url('https://www.astrotheme.com/images/site/arrondi_450_hd.png') no-repeat; text-align: left; font-weight: bold; width: 450px; height: 36px")
(div class="titreFiche" style="padding: 5px 0 0 6px")(a href="https://www.astrotheme.com/astrology/Nolwenn_Leroy" title="Nolwenn Leroy: Astrology, birth chart, horoscope and astrological portrait")Nolwenn Leroy(br /)
(/div)
(div style="text-align: right; border-left: 1px solid #b2c1e2; border-right: 1px solid #b2c1e2; width: 446px; padding: 1px 1px 0; background: #eff8ff")
(table style="width: 100%")(tr)(td style="width: 220px")
(div style="padding: 0; background: url('https://www.astrotheme.com/images/site/arrondi_450_hd.png') no-repeat; text-align: left; font-weight: bold; width: 450px; height: 36px")
(div class="titreFiche" style="padding: 5px 0 0 6px")(a href="https://www.astrotheme.com/astrology/Kim_Kardashian" title="Kim Kardashian: Astrology, birth chart, horoscope and astrological portrait")Kim Kardashian(br /)(span style="font-weight: normal; font-size: 11px")Display her detailed horoscope and birth chart(/span)(/a)(/div)
(/div)
(div style="padding: 0; background: url('https://www.astrotheme.com/images/site/arrondi_450_hd.png') no-repeat; text-align: left; font-weight: bold; width: 450px; height: 36px")
(div class="titreFiche" style="padding: 5px 0 0 6px")(a href="https://www.astrotheme.com/astrology/Julia_Roberts" title="Julia Roberts: Astrology, birth chart, horoscope and astrological portrait")Julia Roberts(br /)(span style="font-weight: normal; font-size: 11px")Display her detailed horoscope and birth chart(/span)(/a)(/div)
(td id="cfcXkw9aycuj35h" style="text-align: right")
(/div)"
Output: (Nolwenn_Leroy", Kim_Kardashian", Julia_Roberts")
The Winner
This is code-golf, so the fewest bytes wins. :)
Can accept the inputs in any way that works, as long as your code can solve arbitrary problems like the test cases.
31 Answers 31
R, 63 bytes
function(s,p,z=el(strsplit(s,' ')))sub(p,'',z[startsWith(z,p)])
The positive-lookbehind implementation is unfortunately 5 bytes longer due to the huge regmatches/gregexpr combination :
function(s,p)regmatches(s,gregexpr(paste0('(?<=',p,')[^ ]*'),s,,T))
-
2\$\begingroup\$ A naive sub(grep()) is slightly better than the lookbehind at 66, but still doesn't encroach on the startsWith(). I don't see much room for improvement here without a change of approach. Try it online! \$\endgroup\$CriminallyVulgar– CriminallyVulgar2018年07月17日 14:06:05 +00:00Commented Jul 17, 2018 at 14:06
-
\$\begingroup\$ A work of art. :') Will be using this to parse html into lists, thank you so much. :) \$\endgroup\$DrQuarius– DrQuarius2018年07月16日 13:44:22 +00:00Commented Jul 16, 2018 at 13:44
-
2\$\begingroup\$ @DrQuarius Regex cannot parse HTML, and so is Jelly. \$\endgroup\$user202729– user2027292018年07月16日 14:30:32 +00:00Commented Jul 16, 2018 at 14:30
-
-
1\$\begingroup\$ @DrQuarius It's a famous joke, and user202729 extended it. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2018年07月17日 11:25:11 +00:00Commented Jul 17, 2018 at 11:25
Japt, 9 bytes
8 bytes if we can take input as an array of words.
̧kbV msVl
̧ // Shorthand for `qS`, split into words.
kbV // Filter the words, selecting only those that start with the prefix.
msVl // For each remaining word, remove prefix length chars from the start.
-
\$\begingroup\$ Very nice, but doesn't seem to work for the last test case. Might be due to quotation marks inside the string? or new lines? \$\endgroup\$DrQuarius– DrQuarius2018年07月17日 04:52:07 +00:00Commented Jul 17, 2018 at 4:52
-
\$\begingroup\$ @DrQuarius Your last test case is faulty, is it not? All the strings you're looking for are in the middle of the words (surrounded by
url('')), none of them are at the start. \$\endgroup\$Etheryte– Etheryte2018年07月17日 08:00:29 +00:00Commented Jul 17, 2018 at 8:00
Python 2, (削除) 57 (削除ここまで) 56 bytes
lambda i,j:[w[len(i):]for w in j.split()if w.find(i)==0]
-1 with thanks to @mypetlion
-
2\$\begingroup\$
lambda i,j:[w[len(i):]for w in j.split()if w.find(i)==0]for -1 byte \$\endgroup\$mypetlion– mypetlion2018年07月16日 15:40:06 +00:00Commented Jul 16, 2018 at 15:40
C (gcc), (削除) 113 (削除ここまで) (削除) 109 (削除ここまで) (削除) 106 (削除ここまで) 105 bytes
-4 bytes thanks to @LambdaBeta!
-3 bytes thanks to @WindmillCookies!
i;f(char*s,char*t){for(i=strlen(s);*t;t++)if(!strncmp(t,s,i))for(t+=i,puts("");*t^32&&*t;)putchar(*t++);}
-
1\$\begingroup\$ You can save 4 bytes by removing both
^0's. Just;*t;and&&*t;\$\endgroup\$LambdaBeta– LambdaBeta2018年07月16日 14:21:26 +00:00Commented Jul 16, 2018 at 14:21 -
\$\begingroup\$ @LambdaBeta thanks! I missed that. \$\endgroup\$betseg– betseg2018年07月16日 14:24:00 +00:00Commented Jul 16, 2018 at 14:24
-
1\$\begingroup\$ I was able to get it down to 107 using a different strategy, sorry :) \$\endgroup\$LambdaBeta– LambdaBeta2018年07月16日 14:48:21 +00:00Commented Jul 16, 2018 at 14:48
-
\$\begingroup\$ @LambdaBeta I actually thought of that method but I didn't think it would've been shorter than the solution that I posted. Nice answer, upvoted. \$\endgroup\$betseg– betseg2018年07月16日 14:50:55 +00:00Commented Jul 16, 2018 at 14:50
-
1\$\begingroup\$ used puts instead of putchar, now is 107, outputs on different lines: tio.run/… \$\endgroup\$Windmill Cookies– Windmill Cookies2018年07月17日 06:39:46 +00:00Commented Jul 17, 2018 at 6:39
Japt, (削除) 16 (削除ここまで) 12 bytes
-4 bytes from @Shaggy
iS qS+V Å® ̧g
iS Insert S value (S = " ") at beginning of first input (Implicit)
q split using
S+V S + Second input
Å slice 1
® map
̧ split using S
g get first position
-
1
-
\$\begingroup\$ Should probably make mention that this is a port of Arnauld's solution. (Assuming it wasn't independently derived, of course) \$\endgroup\$Shaggy– Shaggy2018年07月16日 14:17:55 +00:00Commented Jul 16, 2018 at 14:17
-
\$\begingroup\$ @Shaggy Honestly I did not notice this was the same answer, anyway I'll give him credit. sorry \$\endgroup\$Luis felipe De jesus Munoz– Luis felipe De jesus Munoz2018年07月16日 14:22:48 +00:00Commented Jul 16, 2018 at 14:22
-
\$\begingroup\$ There's a 9 byte solution if you want to give it a try. \$\endgroup\$Shaggy– Shaggy2018年07月16日 15:45:18 +00:00Commented Jul 16, 2018 at 15:45
-
05AB1E, 11 bytes
#ʒηså}εsgF¦
Try it online! (here is a demo for multiline strings)
How does it work?
#ʒηså}εsgF¦ Full program. # Split the first input by spaces. ʒ } Filter the words by ... ηså ... "Does the second input occur in the prefixed of the word?" ε And for each valid word sg Retrieve the length of the of the second input. F¦ And drop the first character of the word that number of times.
-
\$\begingroup\$ :) Very nice, thanks for the multiline demo! I think that was causing issues for other programs. \$\endgroup\$DrQuarius– DrQuarius2018年07月17日 04:55:41 +00:00Commented Jul 17, 2018 at 4:55
Stax, 8 bytes
·B¬╤2*6&
Explanation:
j{x:[fmx|- Full program, implicit input: On stack in order, 1st input in X register
j Split string on spaces
{ f Filter:
x:[ Is X a prefix?
m Map passing elements:
x|- Remove all characters in X the first time they occur in the element
Implicit output
I could also use x%t (length of X, trim from left), which is equally long but packs to 9 bytes.
-
\$\begingroup\$ Beautiful. :) I think this might be the winner. Most of the lowest byte score contenders haven't been able to parse the third test case. :) \$\endgroup\$DrQuarius– DrQuarius2018年07月17日 04:54:41 +00:00Commented Jul 17, 2018 at 4:54
-
\$\begingroup\$ Ahhh... but I see how you've done it now, you had to let the program know that the quotation marks in the string were not part of the program. I think that's fine. Also, yours is still the shortest regardless. :) \$\endgroup\$DrQuarius– DrQuarius2018年07月17日 04:58:01 +00:00Commented Jul 17, 2018 at 4:58
Retina, 31 bytes
L`(?<=^2円¶(.|¶)*([^ ¶]+))[^ ¶]+
Try it online! First line should be the desired prefix, the rest is the input text. Does not remove duplicates. Would be 25 bytes if any white space was a valid seprator. Explanation: We want to list the suffixes of valid prefixes. The [^ ¶]+ matches the suffix itself. The prefix of the regexp is a lookbehind that ensures that the prefix of the suffix is the input prefix. As a lookbehind is evaluated right-to-left, this starts by matching the prefix (using the same pattern but inside ()s to capture it), then any characters, before finally matching the prefix on its own line at the beginning of the input.
-
\$\begingroup\$ White space meaning spaces and/or line breaks? I think that's a valid solution if so, but to be fair to all I will leave the problem as stated. \$\endgroup\$DrQuarius– DrQuarius2018年07月16日 13:40:50 +00:00Commented Jul 16, 2018 at 13:40
-
\$\begingroup\$ @DrQuarius No, any white space includes tabs, formfeeds and even ellipses. \$\endgroup\$Neil– Neil2018年07月16日 14:19:26 +00:00Commented Jul 16, 2018 at 14:19
-
\$\begingroup\$ Retina was the first language that came to mind when I saw the post (though I don't know the language yet). I thought it would be shorter though. Could I bother you for an explanation? For eg. the docs say
¶is a newline character, but I can't figure out why so many are needed here. \$\endgroup\$Sundar R– Sundar R2018年07月16日 16:12:30 +00:00Commented Jul 16, 2018 at 16:12 -
\$\begingroup\$ @sundar Sorry I was in a bit of a rush at the time. The first
¶ensures that the whole first line is matched to the prefix. The second¶is needed because it isn't known how many intermediate lines there are. The last two¶s work the same way - negated character classes normally include newlines but we don't want that here. \$\endgroup\$Neil– Neil2018年07月16日 18:48:16 +00:00Commented Jul 16, 2018 at 18:48 -
\$\begingroup\$ No problem, thanks for adding it in. "normally include newlines but we don't want that here" <- If I understand correctly, we do want that here. OP specifies strictly that only spaces count as separators, that prefixes begin at and suffixes end at spaces. So for eg. "dif\nfractional" shouldn't match for "frac" because the prefix comes after a newline, not a space. Similarly "fracture-\nrelated" should return suffix "ture-\nrelated". Which is good news here I think, because you can remove at least one
¶, possibly more. \$\endgroup\$Sundar R– Sundar R2018年07月16日 19:05:50 +00:00Commented Jul 16, 2018 at 19:05
Brachylog, (削除) 24 (削除ここまで) 21 bytes
tṇ1W&h;Wz{tR&h;.cR∧}s
Could have been a few bytes shorter if there was variable sharing with inline predicates.
Input is an array with the prefix as the first element and the text as the second element.
tṇ1W % Split the text at spaces, call that W
&h;Wz % Zip the prefix with each word, to give a list of pairs
{ }s % Select the outputs where this predicate succeeds:
tR % Call the current word R
&h;.c % The prefix and the output concatenated
R % should be R
∧ % (No more constraints on output)
IBM/Lotus Notes Formula, 54 bytes
c:=@Explode(b);@Trim(@If(@Begins(c;a);@Right(c;a);""))
Takes it's input from two fields named a and b. Works because Formula will recursively apply a function to a list without the need for a @For loop.
No TIO available so here's a screenshot:
APL (Dyalog Unicode), 23 bytes SBCS
Full program. Prompts for text and prefix from stdin. Prints list to stdout.
(5⌽'(\w+)\b',⎕)⎕S'1円'⊢⎕
⎕ prompt (for text)
⊢ yield that (separates '1円' from ⎕)
(...)⎕S'1円' PCRE Search and return list of capture group 1 from the following regex:
⎕ prompt (for prefix)
'(\w+)\b', prepend this string (group of word characters followed by a word boundary)
5⌽ rotate the first 5 characters to the end; '\bPREFIX(\w+)'
C (clang), 107 bytes
i;f(s,t,_)char*s,*t,*_;{i=strlen(s);_=strtok(t," ");while((strncmp(_,s,i)||puts(_+i))&&(_=strtok(0," ")));}
Description:
i;f(s,t,_)char*s,*t,*_;{ // F takes s and t and uses i (int) and s,t,u (char*)
i=strlen(s); // save strlen(s) in i
_=strtok(t," "); // set _ to the first word of t
while( // while loop
(strncmp(_,s,i)|| // short-circuited if (if _ doesn't match s to i places)
puts(_+i)) // print _ starting at the i'th character
&& // the previous expression always returns true
(_=strtok(0," "))) // set _ to the next word of t
; // do nothing in the actual loop
}
Has to be clang because gcc segfaults without #include <string.h> due to strtok problems.
-
\$\begingroup\$ 100 bytes \$\endgroup\$ceilingcat– ceilingcat2018年07月17日 22:29:44 +00:00Commented Jul 17, 2018 at 22:29
Bash + grep, 20 bytes
grep -Po "\b1ドル\K\S*"
Prefix is given as a command-line parameter, and input text is piped in via stdin.
PowerShell 3.0, (削除) 60 (削除ここまで) (削除) 62 (削除ここまで) 59 bytes
param($p,$s)-split$s|%{if($_-cmatch"^$p(.*)"){$Matches[1]}}
Lost some bytes suppressing the cmatch output. Had a janky solution that gained some by purposely causing duplicates. But it also threw redlines if it didn't match on the first but that is not fine now that I think about it. +2 bytes to fix it though.
-
\$\begingroup\$ Solution with 60 bytes returns double answer in some cases
king, tals, ted, tional, tional, tionally, tioned, tioned, tious, tostratic, tures,tures,tures, tures, asand show index error onHe1inexample. Powershell 5.1, 6.0.2. Solution with 62 bytes is Ok. \$\endgroup\$mazzy– mazzy2018年07月18日 07:28:02 +00:00Commented Jul 18, 2018 at 7:28 -
1\$\begingroup\$ @mazzy I knew that, I was just abusing the "Duplicates is allowed" bit to have it return even more duplicates when it comes across a no-match and throw red on a no-match 1st iteration. \$\endgroup\$Veskah– Veskah2018年07月18日 19:56:10 +00:00Commented Jul 18, 2018 at 19:56
MATL, 17 bytes
Yb94ih'(.*)'h6&XX
How?
Yb - Split the input at spaces, place the results in a cell array
94 - ASCII code for ^ character
ih - Get the input (say "frac"), concatenate '^' and the input
'(.*)'h - Push the string '(.*)' into the stack, concatenate '^frac' and '(.*)'. So now we have '^frac(.*), a regex that matches "frac" at the beginning of the string and captures whatever comes after.
6&XX - Run regexp matching, with 6& specifying 'Tokens' mode i.e., the matched capture groups are returned instead of the entire match.
Implicitly output the results.
-
\$\begingroup\$ So that's what
'Tokens'does; good to know! \$\endgroup\$Luis Mendo– Luis Mendo2018年07月16日 18:02:26 +00:00Commented Jul 16, 2018 at 18:02 -
1\$\begingroup\$ Haha. I had no idea either, figured it out by trial and error for this answer. \$\endgroup\$Sundar R– Sundar R2018年07月20日 11:53:44 +00:00Commented Jul 20, 2018 at 11:53
JavaScript (ES6), 57 bytes
Takes input in currying syntax (text)(prefix). Does not remove duplicates.
s=>p=>(' '+s).split(' '+p).slice(1).map(s=>s.split` `[0])
JavaScript (Node.js), (削除) 64 (削除ここまで) 59 bytes
-5 bytes from @Shaggy
a=>b=>b.match(eval(`/\\b${a}\\w*/g`)).map(x=>x.split(a)[1])
-
1
Husk, 11 bytes
Pretty much just a port of the Haskell answer:
m↓L0foΠz=0w
Explanation
m↓L0f(Πz=0)w -- prefix is explicit argument 0, the other one implicit. eg: 0 = "ab" and implicit "abc def"
w -- words: ["abc","def"]
f( ) -- filter by (example w/ "abc"
z=0 -- | zip 0 and element with equality: [1,1]
Π -- | product: 1
-- : ["abc"]
m -- map the following
↓ -- | drop n elements
L0 -- | n being the length of 0 (2)
-- : ["c"]
Jelly, (削除) 11 (削除ここまで) 9 bytes
Ḳœṣ€ḢÐḟj€
A dyadic link accepting the text (a list of characters) on the left and the prefix (a list of characters) on the right which yields a list of lists of characters (the resulting suffixes).
Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.
How?
Ḳœṣ€ḢÐḟj€ - Link: text, prefix e.g. "fracfracit unfracked", "frac"
Ḳ - split (text) at spaces -> list of words ["fracfracit", "unfracked"]
€ - for each (word):
œṣ - split around sublists equal to (prefix) ["","","it"] ["un","ked"]
Ðḟ - filter discard items for which this is truthy:
Ḣ - head
- -- Crucially this modifies the list: ["","it"] ["ked"]
- -- and yields the popped item: "" "un"
- -- and only non-empty lists are truthy: kept discarded
- ...so we end up with the list: [["","it"]]
€ - for each (remaining list of lists of characters):
j - join with the prefix "fracit"
- ["fracit"]
previous 11 byter:
Ḳs€L}Ḣ=\ƇẎ€
Also a dyadic link as above.
Perl 5 with -asE, (削除) 23 (削除ここまで) (削除) 22 (削除ここまで) 21 bytes (?)
say/^$b(.*)/ for@F
Can be run as a commandline one-liner
as perl -asE 'say/^$b(.*)/ for@F' -- -b=frac -, or with a filename in place of the last -.
Or from a script file, say perl -as -M5.010 script.pl -b=frac - (thanks to @Brad Gilbert b2gills for the TIO link demonstrating this).
The code itself is 18 bytes, I added 3 bytes for the -b= option which assigns its value (the prefix input) to a variable named $b in the code. That felt like an exception to the usual "flags aren't counted" consensus.
-a splits each input line at spaces and places the result in the array @F. -s is a shortcut way of assigning a command-line argument as a variable, by giving a name on the command-line. Here the argument is -b=frac, which places the prefix "frac" in a variable $b.
/^$b(.*)/ - Matches the value of $b at the beginning of the string. .* is whatever comes after that, until the end of the word, and the surrounding parantheses capture this value. The captured values are automatically returned, to be printed by say. Iterating through space-separated words with for @F means we don't have to check for initial or final spaces.
-
\$\begingroup\$ tio.run/##XY1BC8IwDIX/Sg4eFNmmh51E8OTPELIuk2BtZ9IK@/… \$\endgroup\$Brad Gilbert b2gills– Brad Gilbert b2gills2018年07月16日 18:29:31 +00:00Commented Jul 16, 2018 at 18:29
Perl 6, 30 bytes
{$^t.comb: /[^|' ']$^p <(\S+/}
Expanded:
{ # bare block lambda with placeholder params $p, $t
$^t.comb: # find all the substrings that match the following
/
[ ^ | ' ' ] # beginning of string or space
$^p # match the prefix
<( # don't include anything before this
\S+ # one or more non-space characters (suffix)
/
}
-
\$\begingroup\$ @sundar fixed \$\endgroup\$Brad Gilbert b2gills– Brad Gilbert b2gills2018年07月16日 18:25:15 +00:00Commented Jul 16, 2018 at 18:25
-
\$\begingroup\$ You seem to have an extra space between 'p' and '<' btw. \$\endgroup\$Sundar R– Sundar R2018年07月16日 18:39:15 +00:00Commented Jul 16, 2018 at 18:39
-
\$\begingroup\$ @sundar The space between
pand<(is necessary as otherwise it may be seen as$v<...>which is short for$v{qw '...'}. \$\endgroup\$Brad Gilbert b2gills– Brad Gilbert b2gills2018年07月17日 06:25:14 +00:00Commented Jul 17, 2018 at 6:25 -
1\$\begingroup\$ Seems to work without it though, at least in this case. \$\endgroup\$Sundar R– Sundar R2018年07月17日 07:33:10 +00:00Commented Jul 17, 2018 at 7:33
-
1\$\begingroup\$ @sundar Technically it just warns, but I don't like writing code that warns when it is only one byte different than code that doesn't warn. \$\endgroup\$Brad Gilbert b2gills– Brad Gilbert b2gills2018年07月18日 15:23:46 +00:00Commented Jul 18, 2018 at 15:23
Java 10, 94 bytes
p->s->{for(var w:s.split(" "))if(w.startsWith(p))System.out.println(w.substring(p.length()));}
Try it online here.
Ungolfed:
p -> s -> { // lambda taking prefix and text as Strings in currying syntax
for(var w:s.split(" ")) // split the String into words (delimited by a space); for each word ...
if(w.startsWith(p)) // ... test whether p is a prefix ...
System.out.println(w.substring(p.length())); // ... if it is, output the suffix
}
Small Basic, 242 bytes
A Script that takes no input and outputs to the TextWindow Object
c=TextWindow.Read()
s=TextWindow.Read()
i=1
While i>0
i=Text.GetIndexOf(s," ")
w=Text.GetSubText(s,1,i)
If Text.StartsWith(w,c)Then
TextWindow.WriteLine(Text.GetSubTextToEnd(w,Text.GetLength(c)+1))
EndIf
s=Text.GetSubTextToEnd(s,i+1)
EndWhile
Try it at SmallBasic.com! Requires IE/Silverlight
-
\$\begingroup\$ Interesting idea but fails for the first test case, input: "1", "He1in aosl 1ll j21j 1lj2j 1lj2 1ll l1j2i" \$\endgroup\$Chas Brown– Chas Brown2018年07月18日 02:20:17 +00:00Commented Jul 18, 2018 at 2:20
-
\$\begingroup\$ Right, I'll try to fiddle with it. I'm sure I'm onto something... \$\endgroup\$Raphaël Côté– Raphaël Côté2018年07月18日 20:23:09 +00:00Commented Jul 18, 2018 at 20:23
Brachylog, 12 bytes
hṇ1∋R&t;.cR∧
Takes input as [text, prefix] through the input variable, and generates each word through the output variable. This was originally sundar's answer, which I started trying to golf after reading that it "could have been a few bytes shorter if there was variable sharing with inline predicates", which is possible now. Turns out that generator output saves even more bytes.
R R
∋ is an element of
h the first element of
the input
ṇ1 split on spaces,
& and the input
t 's last element
c concatenated
; with
. the output variable
R is R
∧ (which is not necessarily equal to the output).
My first two attempts at golfing it down, using fairly new features of the language:
With the global variables that had been hoped for: hA0&tṇ1{∧A0;.c?∧}s (18 bytes)
With the apply-to-head metapredicate: ṇ1tz{tR&h;.cR∧}s (16 bytes)
And my original solution:
Brachylog, 15 bytes
ṇ1hlt↙X⟨∋a0⟩b↙X
Same I/O. This is essentially a generator for words with the prefix, ṇ1h⟨∋a0⟩, modified to remove the prefix.
The input variable
h with its first element replaced with itself
ṇ1 split on spaces
t has a last element
l the length of which
↙X is X,
⟨ ⟩ and the output from the sandwich
⟨∋ ⟩ is an element of the first element of the modified input
⟨ a0⟩ and has the last element of the input as a prefix.
The output variable
⟨ ⟩ is the output from the sandwich
b with a number of characters removed from the beginning
↙X equal to X.
A very different predicate with the same byte count:
Brachylog, 15 bytes
hṇ1∋~c2Xh~t?∧Xt
Same I/O.
∋ An element of
h the first element of
the input variable
ṇ1 split on spaces
~c can be un-concatenated
2 into a list of two strings
X which we'll call X.
h Its first element
~t is the last element of
? the input variable,
∧ and
Xt its last element is
the output variable.
Pyth, (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) (削除) 18 (削除ここまで) (削除) 17 (削除ここまで) 16 bytes
AQVcH)IqxNG0:NG"
-1 by using V instead of FN because V implicitly sets N
-2 after some further reading about string slicing options
-1 using x to check for the presence of the substring at index 0
-1 using replace with "" for getting the end of the string
I'm sure this could use some serious golfing but as a Pyth beginner, just getting it to work was a bonus.
How does it work?
assign('Q',eval_input())
assign('[G,H]',Q)
for N in num_to_range(chop(H)):
if equal(index(N,G),0):
imp_print(at_slice(N,G,""))
Excel VBA, 86 bytes
Takes input as prefix in [A1] and values in [B1] and outputs to the console.
For each w in Split([B1]):?IIf(Left(w,[Len(A1)])=[A1],Mid(w,[Len(A1)+1])+" ","");:Next
Explore related questions
See similar questions with these tags.
https://www.astrotheme.com/astrology/can be a prefix when it's preceded byhref="? \$\endgroup\$