Regular expressions: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 22: Line 22:
hblahstblahk
hblahstblahk
</pre>
</pre>

=={{header|ABAP}}==
=={{header|ABAP}}==


Line 98: Line 99:
<matching>
<matching>
I love pattern matching!</pre>
I love pattern matching!</pre>

=={{header|AppleScript}}==
{{libheader|Satimage.osax}}
<lang applescript>try
find text ".*string$" in "I am a string" with regexp
on error message
return message
end try

try
change "original" into "modified" in "I am the original string" with regexp
on error message
return message
end try</lang>

{{out}}
<pre>
</pre>



=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Line 168: Line 150:
Dalmatians: +100 +2
Dalmatians: +100 +2
Gives 101 dogs
Gives 101 dogs
</pre>

=={{header|AppleScript}}==
{{libheader|Satimage.osax}}
<lang applescript>try
find text ".*string$" in "I am a string" with regexp
on error message
return message
end try

try
change "original" into "modified" in "I am the original string" with regexp
on error message
return message
end try</lang>

{{out}}
<pre>
</pre>
</pre>


Line 217: Line 217:
<pre>Yes, it ends with string!
<pre>Yes, it ends with string!
Thix ix x xtring</pre>
Thix ix x xtring</pre>



=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
Line 417: Line 416:
return 0;
return 0;
}</lang>

=={{header|C sharp}}==
<lang csharp>using System;
using System.Text.RegularExpressions;

class Program {
static void Main(string[] args) {
string str = "I am a string";

if (new Regex("string$").IsMatch(str)) {
Console.WriteLine("Ends with string.");
}

str = new Regex(" a ").Replace(str, " another ");
Console.WriteLine(str);
}
}</lang>
}</lang>


Line 461: Line 477:
"'m now a changed");
"'m now a changed");
std::cout << dest_string << std::endl;
std::cout << dest_string << std::endl;
}</lang>

=={{header|C sharp}}==
<lang csharp>using System;
using System.Text.RegularExpressions;

class Program {
static void Main(string[] args) {
string str = "I am a string";

if (new Regex("string$").IsMatch(str)) {
Console.WriteLine("Ends with string.");
}

str = new Regex(" a ").Replace(str, " another ");
Console.WriteLine(str);
}
}</lang>
}</lang>


Line 593: Line 592:
"This is even another string"<br>
"This is even another string"<br>
"This is even ANOTHER string"<br>
"This is even ANOTHER string"<br>

=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
<lang Emacs Lisp>
<lang Emacs Lisp>
Line 634: Line 634:
NewString = re:replace(String, " a ", " another ", [{return, list}]),
NewString = re:replace(String, " a ", " another ", [{return, list}]),
io:format("~s~n",[NewString]).</lang>
io:format("~s~n",[NewString]).</lang>



=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
Line 689: Line 688:
.( No match.) cr
.( No match.) cr
[THEN]</lang>
[THEN]</lang>



=={{header|Frink}}==
=={{header|Frink}}==
Line 1,289: Line 1,287:
I'm a string
I'm a string
</pre>
</pre>

=={{header|MAXScript}}==
=={{header|MAXScript}}==
<lang MAXScript>
<lang MAXScript>
Line 1,700: Line 1,699:
end
end
{System.showInfo {Regex.replace String " a " fun {$ _ _} " another " end}}</lang>
{System.showInfo {Regex.replace String " a " fun {$ _ _} " another " end}}</lang>

=={{header|Pascal}}==
=={{header|Pascal}}==
<lang pascal>
<lang pascal>
Line 1,783: Line 1,783:
print "Match found\n";
print "Match found\n";
}</lang>
}</lang>

=={{header|Perl 6}}==
<lang perl6>use v6;
if 'a long string' ~~ /string$/ {
say "It ends with 'string'";
}

# substitution has a few nifty features

$_ = 'The quick Brown fox';
s:g:samecase/\w+/xxx/;
.say;
# output:
# Xxx xxx Xxx xxx
</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,920: Line 1,905:


(displayln (regexp-replace " a " s " another "))
(displayln (regexp-replace " a " s " another "))
</lang>

=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>use v6;
if 'a long string' ~~ /string$/ {
say "It ends with 'string'";
}

# substitution has a few nifty features

$_ = 'The quick Brown fox';
s:g:samecase/\w+/xxx/;
.say;
# output:
# Xxx xxx Xxx xxx
</lang>
</lang>


Line 2,265: Line 2,266:
Replace text:
Replace text:
<lang shiny>say str.alter ~ a ~ 'another'</lang>
<lang shiny>say str.alter ~ a ~ 'another'</lang>

=={{header|Sidef}}==
=={{header|Sidef}}==
Simple matching:
Simple matching:
Line 2,395: Line 2,397:
* replace the first vowel with "?"
* replace the first vowel with "?"
di regexr(s,"[aeiou]","?")</lang>
di regexr(s,"[aeiou]","?")</lang>

=={{header|Swift}}==
=={{header|Swift}}==


Line 2,572: Line 2,575:
echo "$modified" # I am the modified string
echo "$modified" # I am the modified string
fi</lang>
fi</lang>



=={{header|Vala}}==
=={{header|Vala}}==