Skip to content

Instantly share code, notes, and snippets.

View netuoso's full-sized avatar
💥
Programming...

Andrew Chaney netuoso

💥
Programming...
View GitHub Profile
@roblogic
roblogic / zshexpn-explained.md
Created November 19, 2020 01:49
Regular Expressions in Zsh

The following is taken from a brilliant answer on unix.se. Posting it here for personal reference. The question was:

${var//pattern/replacement} is using zsh wildcard patterns for pattern, the same ones as used for filename generation aka globbing which are a superset of the sh wildcard patterns. The syntax is also affected by the kshglob and extendedglob options. The ${var//pattern/replacement} comes from the Korn shell initially.

I'd recommend enabling extendedglob (set -o extendedglob in your ~/.zshrc) which gives you the most features (more so than standard EREs) at the expense of some backward incompatibility in some corner cases.

You'll find it documented at info zsh 'filename generation'.