Regular expressions: Difference between revisions

Content added Content deleted
 
Line 1,390: Line 1,390:
The following examples use re2 regex literals.
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 switch expression test.
There are several functions that can be used with regexes, such as match(), replace(), split(), etc. They can also be matched using the forward operator (->).


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


Or...
Or...
Line 1,400: Line 1,400:
Or...
Or...
<syntaxhighlight lang="langur">switch "somestring" {
<syntaxhighlight lang="langur">switch "somestring" {
case re/abc/: ...
case -> re/abc/: ...
...
...
}</syntaxhighlight>
}</syntaxhighlight>


Or...
Or...
<syntaxhighlight lang="langur">switch re/abc/ {
<syntaxhighlight lang="langur">switch -> re/abc/ {
case "somestring": ...
case "somestring": ...
...
...