Regular expressions: Difference between revisions

Content added Content deleted
No edit summary
(+Icon+Unicon)
Line 380: Line 380:
WRITE(ClipBoard) string ! Th** q****ck br**wn f**x j**mps **v**r th** l**zy d**g</lang>
WRITE(ClipBoard) string ! Th** q****ck br**wn f**x j**mps **v**r th** l**zy d**g</lang>


== Icon and Unicon ==
The {{libheader|Icon Programming Library}} provides [http://www.cs.arizona.edu/icon/library/procs/regexp.htm regexp]. Regex includes procedures to provide access to regular expressions within native string scanning and matching expressions. 'ReFind' and 'ReMatch' respectively generate the sequence of beginning and ending positions matched by a regular expression. Additionally, there is a regular expression pattern compiler 'RePat' and other supporting functions and variables.

==={{header|Icon}}===
<lang Icon>procedure main()

s := "A simple string"
p := "string$" # regular expression

s ? write(image(s),if ReFind(p) then " matches " else " doesn't match ",image(p))

s[j := ReFind(p,s):ReMatch(p,s,j)] := "replacement"
write(image(s))
end

link regexp # link to IPL regexp </lang>

Sample output:<pre>"A simple string" matches "string$"
"A simple replacement"</pre>

==={{header|Unicon}}===
The Icon solution works in Unicon.
=={{header|J}}==
=={{header|J}}==