In Perl, regex modifiers are used to change the behavior of regular expressions. The following are common modifiers:
Here's an example demonstrating these modifiers:
$pattern = qr/^hello/i; // Case insensitive match
if ("Hello there!" =~ $pattern) {
print "Matched!\n";
}
$multiline_text = "line1\nline2\nline3";
if ($multiline_text =~ /line2/m) {
print "Found line2 in multiline text!\n";
}
$multi_line_pattern = qr/line1.*line3/s; // Dot matches across lines
if ($multi_line_pattern =~ /$multi_line_pattern/) {
print "Matched across multiple lines!\n";
}
$extended_pattern = qr/ \bfoo\b # This is a comment
/x;
if (" foo " =~ $extended_pattern) {
print "Matched foo with extended pattern!\n";
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?