Regular expressions: Difference between revisions

Content added Content deleted
No edit summary
Line 1,099: Line 1,099:
</pre>
</pre>


=={{header|Langur}}==
=={{header|langur}}==
Langur uses semi-integreted regex. There are several functions that can be used with regexes, such as match(), replace(), split(), etc.
Langur uses semi-integreted regex. There are several functions that can be used with regexes, such as match(), replace(), split(), etc.


To match a string, ...
To match a string, ...
<lang Langur>if matching(re/abc/, "somestring") { ... }</lang>
<lang langur>if matching(re/abc/, "somestring") { ... }</lang>


Or...
Or...
<lang Langur>if val (.x, .y) = submatch(re/(abc+).+?(def)/, "somestring") { ... }</lang>
<lang langur>if val (.x, .y) = submatch(re/(abc+).+?(def)/, "somestring") { ... }</lang>

Or...
<lang langur>given "somestring" {
case re/abc/: ...
...
}</lang>

Or...
<lang langur>given re/abc/ {
case "somestring": ...
...
}</lang>


Substitution does not alter the original string.
Substitution does not alter the original string.
<lang Langur>replace("abcdef", re/abc/, "Y")
<lang langur>replace("abcdef", re/abc/, "Y")
# result: "Ydef"</lang>
# result: "Ydef"</lang>