RegEx

Objective: Use regex to pick the name from the sentence: "Hello John!"

Python

import re

text = "Hello John!"

if m := re.search("(\w+)!$", text):
    name = m.groups()[0]
    print(f"Name: {name}")

Rust

There is no regex in stdlib. Crate regex has been used.

use regex::Regex;

fn main() {
    let text = "Hello John!";
    let re = Regex::new(r"(\w+)\!$").unwrap();
    
    if let Some(m) = re.captures(text) {
        println!("Name: {}", &m[1]);
    }
}

Crystal

text = "Hello John!"

/(\w+)\!$/.match(text).try do |x|
  name = x[1]
  puts "Name: #{name}"
end