Regular Expressions
== Descrition ==
This page describes the server and client facilities for dealing with
regular expressions.
== Synopsis ==
=== Server & Client ===
(pregexp string)
(pregexp-match regexp-or-string string)
(pregexp-split regexp-or-string string)
(pregexp-replace regexp-or-string string1 string2)
(pregexp-replace* regexp-or-string string1 string2)
== Examples ==
regexp
== Server & Client Definitions ==
=== ++(pregexp string)++ ===
pregexp
pregexp
^ arguments ^ type ^ description ^
| string | string | A string denoting a regular expression. |
The function ++pregexp++ compiles the regular expression into a form suitable
to ++pregexp-match++.
=== ++(pregexp-match re-or-str string)++ ===
pregexp-match
pregexp-match
^ arguments ^ type ^ description ^
| re-or-str | string or regexp | The regular expression, compiled or not. |
| string | string | The string to be parsed. |
This function parses the argument ++string++ according to the regular expression
++re-or-str++. On success, this function returns a list whose head is the
overall match and its tails the successive sub-matches. On failure, it
returns ++#f++.
Examples:
(pregexp-match "brain" "bird") ⇒ #f
(pregexp-match "needle" "hay needle stack") ⇒ ("needle")
(pregexp-match "([^:]+)://([^:]+)(?:[:]([0-9]+))?" "http://foo.bar") ⇒ ("http://foo.bar" "foo.bar" #f)
(pregexp-match "([^:]+)://([^:]+)(?:[:]([0-9]+))?" "http://foo.bar:8080") ⇒ ("http://foo.bar" "foo.bar" "8080")
=== ++(pregexp-split re-or-str string)++ ===
pregexp-split
pregexp-split
^ arguments ^ type ^ description ^
| re-or-str | string or regexp | The regular expression, compiled or not. |
| string | string | The string to be parsed. |
This function splits the argument ++string++ into a list of strings, breaking
at delimiter regular expressions. Examples:
(pregexp-split ":" "/bin:/usr/bin:/usr/bin/X11:/usr/local/bin") ⇒ ("/bin" "/usr/bin" "/usr/bin/X11" "/usr/local/bin")
(pregexp-split " " "pea soup") ⇒ ("pea" "soup")
=== ++(pregexp-replace re-or-str string1 string2)++ ===
pregexp-replace
pregexp-replace
^ arguments ^ type ^ description ^
| re-or-str | string or regexp | The regular expression, compiled or not. |
| string | string | The string to be parsed. |
Replaces the first occurrence of ++re-or-str++ in ++string1++ by ++string2.++
Examples:
(pregexp-replace "te" "liberte" "ty") ⇒ "liberty"
=== ++(pregexp-replace* re-or-str string1 string2)++ ===
pregexp-replace*
pregexp-replace*
^ arguments ^ type ^ description ^
| re-or-str | string or regexp | The regular expression, compiled or not. |
| string | string | The string to be parsed. |
Replaces the all the occurrences of ++re-or-str++ in ++string1++ by ++string2.++
Examples:
(pregexp-replace* "te" "liberte egalite fraternite" "ty") ⇒ "liberty egality fratyrnity"
== See also ==
regexp, xml-parse