String matching: Difference between revisions

Added Emacs Lisp
(Added EchoLisp)
(Added Emacs Lisp)
Line 878:
# => true
</lang>
 
=={{header|Emacs Lisp}}==
<lang Emacs Lisp>
(defun match (word str)
(progn
(setq regex (format "^%s.+$" word) )
(if (string-match regex str)
(insert (format "%s found in beginning of: %s\n" word str) )
(insert (format "%s not found in beginning of: %s\n" word str) ))
 
(setq pos (string-match word str) )
 
(if (string-match word str)
(insert (format "%s found at position %d in: %s\n" word pos str) )
(insert (format "%s not found in: %s\n" word str) ))
(setq regex (format "^.+%s$" word) )
(if (string-match regex str)
(insert (format "%s found in end of: %s\n" word str) )
(insert (format "%s not found in end of: %s\n" word str) ))))
 
(setq string "before center after")
 
(progn
(match "center" string)
(insert "\n")
(match "before" string)
(insert "\n")
(match "after" string) )
</lang>
<b>Output:</b>
<pre>
center not found in beginning of: before center after
center found at position 7 in: before center after
center not found in end of: before center after
 
before found in beginning of: before center after
before found at position 0 in: before center after
before not found in end of: before center after
 
after not found in beginning of: before center after
after found at position 14 in: before center after
after found in end of: before center after
</pre>
 
=={{header|Erlang}}==
678

edits