String matching: Difference between revisions

add bqn
(Emacs Lisp: Simplify example)
(add bqn)
Line 1,202:
"The fox jumps over the dog" contains "dog" 1 time(s)</pre>
 
=={{header|BQN}}==
 
<code>⍷</code> does much of the heavy lifting here. It is commuted with <code>˜</code> so the order of the arguments makes sense.
<lang bqn>SW ← ⊑⍷˜
⊑⍷˜
Contains ← ∨´⍷˜
∨´⍷˜
EW ← ¯1⊑⍷˜
¯1⊑⍷˜
Locs ← /⍷˜
/⍷˜
"abcd" SW "ab"
1
"abcd" SW "cd"
0
"abcd" EW "ab"
0
"abcd" EW "cd"
1
"abcd" Contains "bb"
0
"abcd" Contains "ab"
1
"abcd" Contains "bc"
1
"abab" Contains "ab"
1
"abab" Locs "ab"
⟨ 0 2 ⟩</lang>
=={{header|Bracmat}}==
Bracmat does pattern matching in expressions <code><i>subject</i>:<i>pattern</i></code> and in strings <code>@(<i>subject</i>:<i>pattern</i>)</code>. The (sub)pattern <code>?</code> is a wild card.
236

edits