Regular expressions: Difference between revisions

Added Vala Code
(Added Vala Code)
Line 1,299:
@(end)</lang>
 
=={{header|Vala}}==
<lang vala>
void main(){
string sentence = "This is a sample sentence.";
 
Regex a = new Regex("s[ai]mple"); // if using \n type expressions, use triple " for string literals as easy method to escape them
 
if (a.match(sentence)){
stdout.printf("\"%s\" is in \"%s\"!\n", a.get_pattern(), sentence);
}
 
string sentence_replacement = "cat";
sentence = a.replace(sentence, sentence.length, 0, sentence_replacement);
stdout.printf("Replaced sentence is: %s\n", sentence);
}
</lang>
 
Output:
<pre>
"s[ai]mple" is in "This is a sample sentence."!
Replaced sentence is: This is a cat sentence.
</pre>
=={{header|Vedit macro language}}==
Vedit can perform searches and matching with either regular expressions, pattern matching codes or plain text. These examples use regular expressions.