use strict;
my $str = '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>
);
}
';
my $regex = qr/PLF2/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
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 Perl, please visit: http://perldoc.perl.org/perlre.html