Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
getopt(?:s|)(?: (?:-[a-zA-Z])*)*(?'name'[$a-zA-Z]+|)\s(?:(?:-o|--options) (?'short'.+) (?:-l|--longoptions|--long) (?'long'(?:[a-zA-Z0-9]|,|:|\$)+) \-\- \"\$@\"|(?:(?:(?:-[a-zA-Z])*|)\s*\"(?'while'(?:[a-zA-Z0-9]|,|:|\$)+)\"))
/
gm

Description

This will parse the parameters/arguments that a Bash script when it uses getopt(s).

Groups: name,short,long,while

Example cases:

while getopts -a ":n:t:" options; do
while getopts -a -n ":n:t:" options; do
while getopt ":n:t:" options; do
Parameters=$(getopt -a -n $ScriptName --options $SHORT --longoptions $LONG -- "$@")
Parameters=$(getopt -a -n alphabet -o abc:d: --long alpha,bravo,charlie:,delta: -- "$@")
Submitted by Spyingwind - 2 years ago