Regular Expressions 101

Community Patterns

Zshell - Parameter Name Regexp for TextMate Snippets

0

Regular Expression
ECMAScript (JavaScript)

/
(?<=^ *)(?=\$(?:\{[a-z_][a-z0-9_]*\}|[a-z_][a-z0-9_]*)|[a-z_][a-z0-9_]*)(?:(?:\$\{)?([^ \}]+)\}?)(?= *$)
/
gim

Description

Zshell parameter name captures

Attempts to capture a zsh parameter identifier inside a text selection—intended for use in TextMate snippets that want to do additional selection based replacements (using $TM_SELECTED_TEXT, or other expansion variables). Currently the pattern captures for all cases in the first group.

Includes some basic unit tests checking for first capture group, for common cases with surrounding whitespace:

  • Bare word parameter identifiers - ex. "parameter_name1"

  • Basic expansions - "$parameter_name2"

  • Bracketed expansions - ex. "${parameter_name3}"

Submitted by anonymous - 3 years ago