Regular expressions: Difference between revisions

Content added Content deleted
(jq)
No edit summary
Line 544: Line 544:
<pre>hello hello! world world!
<pre>hello hello! world world!
hello HELLO world WORLD</pre>
hello HELLO world WORLD</pre>

=={{header|Emacs Lisp}}==
<lang Emacs Lisp>
(defun match (str word)
(if (string-match word str)
(progn
(insert (format "%s found in: %s\n" word 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) )))

(setq str1 "before center after" str2 "before centre after")

(progn
(match str1 "center")
(match str2 "center"))
</lang>
<b>Output:</b>
<pre>
center found in: before center after
result: left center right
center not found in: before centre after
</pre>


=={{header|Erlang}}==
=={{header|Erlang}}==