in reply to Regex for matching URLs with username/password and token
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; for my $string ( '--server api.blr-ocp1.lab.rbbn.com --username mgore --password ab +c123', '--server api.blr-ocp1.lab.rbbn.com --token kfjshdssahdvkbvjkbj' ) { if ($string =~ /^--server\s+(?<server>\S+)\s+ (?:--username\s+(?<username>\S+)\s+--password\s+(?<passwor +d>\S+) |--token\s+(?<token>\S+))/x ) { say 'Server: ', ${^CAPTURE}{server}; if (exists ${^CAPTURE}{token}) { say 'Token: ', ${^CAPTURE}{token}; } else { say 'Username: ', ${^CAPTURE}{username}; say 'Password: ', ${^CAPTURE}{password}; } } else { say 'No match'; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex for matching URLs with username/password and token
by jdporter (Paladin) on Mar 10, 2025 at 20:22 UTC |