| Bytes | Lang | Time | Link |
|---|---|---|---|
| 026 | Arturo | 250919T000002Z | chunes |
| 013 | Dyalog APL | 250918T221537Z | Aaron |
| 003 | 05AB1E | 250918T090435Z | Kevin Cr |
| 002 | Japt f | 250918T082113Z | Shaggy |
| 120 | Pascal | 250918T060016Z | Kai Burg |
| 005 | W | 200123T013915Z | user8505 |
| 049 | Racket | 160501T052411Z | Winny |
| 032 | JavaScript ES6 | 160214T190459Z | Neil |
| 029 | Mathematica | 160215T020038Z | LegionMa |
| 028 | R | 160215T003302Z | mnel |
| 045 | 𝔼𝕊𝕄𝕚𝕟 | 160215T001515Z | Mama Fun |
| 005 | sh | 160215T000233Z | Rainer P |
| 013 | vim | 160214T193201Z | Doorknob |
| 005 | Pyth | 160214T190018Z | Maltysen |
| 027 | Bash | 160214T193916Z | Doorknob |
| 036 | Python 2 | 160214T191804Z | Andreas |
| 004 | TeaScript | 160214T190250Z | Downgoat |
| 047 | Python 2 | 160214T191758Z | Blue |
Dyalog APL, 13 bytes
Accepts the list to search through on the left and what to search for on the right.
⊣(/⍨)∨/⍤⍷¨⍨∘⊂
⍷¨⍨ # Find-each backwards (search for the right arg within the left)
∘⊂ # after enclosing the right so that it is distributed to each of the left
∨/ # Followed by or-over so that any occurrence marks that word as having the search phrase
(/⍨) # Compress backwards
⊣ # over the left arg
💎
Created with the help of Luminespire.
05AB1E, 3 bytes
ʒIå
Inputs in the order \$list, searchInput\$.
Try it online or verify all test cases.
An equal-bytes alternative would be:
δåÏ
Inputs in the order \$searchInput, list\$.
Try it online or verify all test cases.
Explanation:
ʒ # Filter the first (implicit) input-list by:
Iå # It contains the second input-string as substring
# (after which the filtered list is output implicitly as result)
δ # Using the first (implicit) input-string as argument, map each value in the
# second (implicit) input-string to:
å # Contains-check, using the argument on the current value
# (resulting in a list of 1s and 0s whether it contained the substring)
Ï # Keep the values in the second (implicit) input-string at the truthy positions
# (after which the filtered list is output implicitly as result)
Pascal, 120 B
This program requires a processor supporting features of Extended Pascal as described in ISO standard 10206, in particular the string schema support and the index function.
The search pattern is entered on the first line and subsequent lines are list members.
The golfed program assumes a non‐empty list and uses a repeat … until loop because of that.
The input strings are capped to 99 characters.
program p(input,output);var p,s:string(99);begin
readLn(p);repeat readLn(s);if 0<index(s,p)then writeLn(s)until EOF end.
Sane version:
{ The special `program` parameters `input` and `output` are `text` files.
`Text` files are (possibly empty) sequences of (possibly empty) lines.
This is guaranteed by the processor: A missing end‐of‐line character
sequence at the end of a file is automatically inserted. }
program makeASearchEngine(input, output);
var
needle, line: string(maxInt);
begin
{ Attempting to read past the end of a file causes an error. }
if not EOF(input) then
begin
readLn(input, needle);
while not EOF(input) do
begin
readLn(input, line);
{ `index(source, pattern)` finds the first occurrence of
`pattern` in `source` and returns the starting index.
In Pascal `string` indices are 1‐based, so 0 is invalid. }
if index(line, needle) > 0 then
begin
writeLn(output, line)
end
{ Note that in Pascal the semicolon serves as a separator.
It can be omitted if you do not want to separate anything. }
end
end
end.
The program works correctly for ε (empty word, i. e. a zero‐length string).
ε is present everywhere so all list members are printed.
W, 5 bytes
b@t!W
Explanation
ba % Implicit inputs
b % Access the second operand
@ % Show two operands (yields [b,b,a])
W % Select everything in a that fullfills this condition:
t % Trim everything in the current item
% that appears in the input
% Yields ([b,b.trim(a)])
! % Negate this result, determining whether
% the input is a subset of the current item
% Keeping all of the items that fullfill
% this condition yields a list by default
```
Racket, 49 bytes
(λ(l s)(filter-map(curryr string-contains? s)l))
JavaScript ES6, 32 bytes
(s,a)=>a.filter(e=>~e.search(s))
33 bytes if the string might contain regexp metacharacters:
(s,a)=>a.filter(e=>~e.indexOf(s))
Mathematica, 29 bytes
Select[#2,StringContainsQ@#]&
Very simple.
R, 38 28 bytes
function(x,y)grep(y,x,,,T,T)
simply a wrapper for grep, with value = TRUE to return the value [not a logical flag], and fixed (to allow regex-like strings to be searched and not processed as regex.
edit - 10 bytes by passing empty arguments to allow positional matching
𝔼𝕊𝕄𝕚𝕟, 4 chars / 5 bytes
í⒡ăî
Simple.
Explanation
Filter input array by string input.
sh, 5 bytes
Accepts a list of words on stdin, one per line, and a search string as command line argument.
fgrep
This submisson should be valid by the rules on scoring builtin functions.
vim, 13
dd:v/\V<C-r>"<BS>/d<cr>
Expects input as
th
thing
awesome
potato
example
Outputs on separate lines.
dd delete first line into " (default) register
:v/ apply to every line that doesn't match the following regexp...
\V "very nomagic" - strips chars of their special regex meaning
<C-r>" paste contents of " register into the command
<BS> remove the trailing newline from the first line
/d ... delete the lines
Bash, 27 bytes
tr \ \\n<<<${@:2}|fgrep $1
Sample run:
llama@llama:...code/shell/ppcg72079search$ ./search.sh th thing awesome potato example
thing
With multiple outputs, they will be on separate lines.
tr \ \\n replace spaces with newlines (equivalent to tr ' ' '\n')
<<<${@:2} ... with STDIN as all but first argument
|fgrep $1 fgrep for first argument (fgrep is grep w/ "fixed" string, not regex)
Python 2, 42 36 bytes
lambda i,a:filter(lambda v:i in v,a)
Thanks to muddyfish for saving 6 bytes
Test:
a=lambda i,a:filter(lambda v:i in v,a)
a('th', ['thing', 'awesome', 'potato', 'example']) # ['thing']
a('ing', ['thing', 'potato']) # ['thing']
a('tat', ['thing', 'potato']) # ['potato']
a('tat', ['tato', 'potato']) # ['tato', 'potato']
TeaScript, 4 bytes
F@Iσ
Output is cast to string.
Explanation
F@ // Filter input 1
Iσ // Includes input 2
Python 2, 47 bytes
a=input()
print[x for x in input()if x in a]