Regular expressions: Difference between revisions

Emacs Lisp: Simplify solution
(Emacs Lisp: Simplify solution)
Line 854:
 
=={{header|Emacs Lisp}}==
<lang Emacs Lisp>(let ((string "I am a string"))
(defunwhen (string-match-p (word"string$" strstring)
(setqmessage pos"Ends (with 'string-match word str'") )
(message "%s" (replace-regexp-in-string " a " " another " string)))</lang>
(if pos
(progn
(insert (format "%s found at position %d in: %s\n" word pos str) )
(setq regex (format "^.+%s" word) )
(setq str (replace-regexp-in-string regex (format "left %s" word) str) )
(setq regex (format "%s.+$" word) )
(setq str (replace-regexp-in-string regex (format "%s right" word) str) )
(insert (format "result: %s\n" str) ))
(insert (format "%s not found in: %s\n" word str) )))
 
{{out}}
(setq str1 "before center after" str2 "before centre after")
 
Ends with 'string'
(progn
I am another string
(match "center" str1)
(insert "\n")
(match "center" str2) )
</lang>
<b>Output:</b>
<pre>
center found at position 7 in: before center after
result: left center right
 
center not found in: before centre after
</pre>
 
=={{header|Erlang}}==
Anonymous user