Search notes:

Perl regular expressions: non capturing groups

(?:pattern): match (pattern) but don't capture it.
#!/usr/bin/perl
use warnings;
use strict;

use feature 'say';


say extract_number('abc 17 foo 42 more 999'              ); # 42
say extract_number('bar 201 xyz 3 88'                    ); # 201
say extract_number('hello world 1234 - number 17 baz 39.'); # 39


sub extract_number {
  # extract a number after foo, bar or baz

  my $text = shift;

  my ($num) = $text =~ /(?:foo|bar|baz) (\d+)/;
  return $num;
}
Github repository about-perl, path: /regular-expressions/non-capturing-group.pl

See also

Perl regular expressions

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...', 1758200862, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/regular-expressions/non-capturing-group(60): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78