Regular expressions: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Minor tidy) |
Langurmonkey (talk | contribs) |
||
Line 1,388: | Line 1,388: | ||
=={{header|langur}}== |
=={{header|langur}}== |
||
The following examples use re2 regex literals. |
|||
There are several functions that can be used with regexes, such as match(), replace(), split(), etc. They can also be matched in a |
There are several functions that can be used with regexes, such as match(), replace(), split(), etc. They can also be matched in a switch expression test. |
||
To match a string, ... |
To match a string, ... |
||
Line 1,396: | Line 1,396: | ||
Or... |
Or... |
||
{{works with|langur|0.10}} |
|||
<syntaxhighlight lang="langur">if val .x, .y = submatch(re/(abc+).+?(def)/, "somestring") { ... }</syntaxhighlight> |
<syntaxhighlight lang="langur">if val .x, .y = submatch(re/(abc+).+?(def)/, "somestring") { ... }</syntaxhighlight> |
||
Prior to 0.10, multi-variable declaration/assignment would use parentheses around variable names and values. |
|||
<syntaxhighlight lang="langur">if val (.x, .y) = submatch(re/(abc+).+?(def)/, "somestring") { ... }</syntaxhighlight> |
|||
Or... |
Or... |
||
<syntaxhighlight lang="langur"> |
<syntaxhighlight lang="langur">switch "somestring" { |
||
case re/abc/: ... |
case re/abc/: ... |
||
... |
... |
||
Line 1,409: | Line 1,405: | ||
Or... |
Or... |
||
<syntaxhighlight lang="langur"> |
<syntaxhighlight lang="langur">switch re/abc/ { |
||
case "somestring": ... |
case "somestring": ... |
||
... |
... |