Anonymous user
Regular expressions: Difference between revisions
Added Rust
(→{{header|Smalltalk}}: classify existing code as GNU Smalltalk; add pharo) |
(Added Rust) |
||
Line 2,044:
<pre>'I am a string' ends with 'string'
replace 'am' with 'was' = I was a string</pre>
=={{header|Rust}}==
Note that <code>Regex::new</code> checks for a valid regex and thus returns a <code>Result<Regex, Error></code>.
<lang Rust>use regex::Regex;
fn main() {
let s = "I am a string";
if Regex::new("string$").unwrap().is_match(s) {
println!("Ends with string.");
}
println!("{}", Regex::new(" a ").unwrap().replace(s, " another "));
}</lang>
=={{header|Sather}}==
|