// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m)PLF2").unwrap();
let string = "import React from 'react';
import { useState } from 'react';
export default function UserForm() {
const [students, setStudents] = useState([
{ id: 1, name: 'Anna', age: 18 },
{ id: 2, name: 'Tom', age: 17 },
]);
const [name, setName] = useState('');
const [age, setAge] = useState(0);
const handleSubmit = (event) => {
event.preventDefault();
};
const newStudent = {
id: Date.now(),
name: name,
age: age,
};
setStudents([...students, newStudent]);
setName('');
setAge(0);
return (
<div>
<ul>
{students.map((student) => (
<li key={student.id}>
{student.name}
{student.age}
</li>
))}
</ul>
<form onSubmit={handleSubmit}>
<input
type=\"text\"
value={name}
onChange={(e) => setName(e.target.value)}
/>
<input
type=\"number\"
value={age}
onChange={(e) => setAge(e.target.value)}
/>
<button type=\"submit\"> Hinzufügen</button>
</form>
;
</div>
);
}
";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/