132
132
<v>RepCount = integer()</v>
135
<p>Substitutes the first occurrence of a substring matching <c>RegExp</c> in <c>String</c> with the string <c>New</c>. A <c><![CDATA[&]]></c> in the string <c>New</c> is replaced by the matched substring of <c>String</c>. <c><![CDATA[\\&]]></c> puts a literal <c><![CDATA[&]]></c> into the replacement string. It returns as follows:</p>
135
<p>Substitutes the first occurrence of a substring matching <c>RegExp</c> in <c>String</c> with the string <c>New</c>. A <c><![CDATA[&]]></c> in the string <c>New</c> is replaced by the matched substring of <c>String</c>. <c><![CDATA[\&]]></c> puts a literal <c><![CDATA[&]]></c> into the replacement string. It returns as follows:</p>
137
137
<tag><c>{ok,NewString,RepCount}</c></tag>
341
341
<p>The escape sequences allowed are the same as for Erlang
344
<tag><c>\\b</c></tag>
348
<tag><c>\\f</c></tag>
350
350
<p>form feed </p>
354
354
<p>newline (line feed) </p>
356
<tag><c>\\r</c></tag>
358
358
<p>carriage return </p>
360
<tag><c>\\t</c></tag>
364
<tag><c>\\e</c></tag>
368
<tag><c>\\v</c></tag>
370
370
<p>vertical tab </p>
372
<tag><c>\\s</c></tag>
376
<tag><c>\\d</c></tag>
380
<tag><c>\\ddd</c></tag>
380
<tag><c>\ddd</c></tag>
382
382
<p>the octal value ddd </p>
384
<tag><c>\\xhh</c></tag>
384
<tag><c>\xhh</c></tag>
386
386
<p>The hexadecimal value <c>hh</c>.</p>
388
<tag><c>\\x{h...}</c></tag>
388
<tag><c>\x{h...}</c></tag>
390
390
<p>The hexadecimal value <c>h...</c>.</p>
392
<tag><c>\\c</c></tag>
394
<p>any other character literally, for example <c>\\\\</c> for backslash,
395
<c>\\"</c> for ")</p>
394
<p>any other character literally, for example <c>\\</c> for backslash,
398
398
<p>To make these functions easier to use, in combination with the
399
399
function <c>io:get_line</c> which terminates the input line with
400
400
a new line, the <c>$</c> characters also matches a string ending
401
with <c>"...\ "</c>. The following examples
401
with <c>"...\n"</c>. The following examples
402
402
define Erlang data types:</p>
404
404
Atoms [a-z][0-9a-zA-Z_]*
406
406
Variables [A-Z_][0-9a-zA-Z_]*
408
Floats (\\+|-)?[0-9]+\\.[0-9]+((E|e)(\\+|-)?[0-9]+)?</pre>
409
<p>Regular expressions are written as Erlang strings when used with the functions in this module. This means that any <c>\\</c> or <c>"</c> characters in a regular expression
410
string must be written with <c>\\</c> as they are also escape characters for the string. For example, the regular expression string for Erlang floats is:
411
<c>"(\\\\+|-)?[0-9]+\\\\.[0-9]+((E|e)(\\\\+|-)?[0-9]+)?"</c>.</p>
408
Floats (\+|-)?[0-9]+\.[0-9]+((E|e)(\+|-)?[0-9]+)?</pre>
409
<p>Regular expressions are written as Erlang strings when used with the functions in this module. This means that any <c>\</c> or <c>"</c> characters in a regular expression
410
string must be written with <c>\</c> as they are also escape characters for the string. For example, the regular expression string for Erlang floats is:
411
<c>"(\\+|-)?[0-9]+\\.[0-9]+((E|e)(\\+|-)?[0-9]+)?"</c>.</p>
412
412
<p>It is not really necessary to have the escape sequences as part of the regular expression syntax as they can always be generated directly in the string. They are included for completeness and can they can also be useful when generating regular expressions, or when they are entered other than with Erlang strings.</p>