Search notes:

Perl matching: Dynamic case sensitiveness

The (?...) construct allows to change the case sensitiveness in regular expressions.
#!/usr/bin/perl
use warnings;
use strict;

match_txt('foo-bar', '');
match_txt('foo-BAR', '');
match_txt('foo-bar', 'i');

sub match_txt {
  my $txt            = shift;
  my $case_sensitive = shift;

  if ($txt =~ m!(?$case_sensitive:foo-BAR)!) {
    print "$txt matches       | case_sensitive = $case_sensitive\n";
  }
  else {
    print "$txt doesn't match | case_sensitive = $case_sensitive\n";
  }
}

# foo-bar doesn't match | case_sensitive = 
# foo-BAR matches       | case_sensitive = 
# foo-bar matches       | case_sensitive = i
Github repository about-perl, path: /functions/m__dynamic_case_sensitiveness.pl

See also

Perl matching: match and assign
Perl functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758200332, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/functions/m__dynamic_case_sensitiveness(66): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78