Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pattern Matching or RegEx Man Page in linux/unix?

I've got an exam and I'm only allowed to use the man pages. I'm wondering how I can find the pattern matching details in the man pages?

Something similar to this info:

http://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching

like image 273
wesbos Avatar asked Oct 24 '25 01:10

wesbos


2 Answers

for regexes in sed and grep and most standard Unix tools

man 7 regex tells you about regexes used in sed, grep, and most standard tools.

See the man page for the tool itself as well, because there might be some exceptions.

for regexes in other tools

Many tools that didn't originally come with Unix have their own syntax.

For example, for perl look at man perlre and for vim type :help pattern from inside vim.

for shell patterns

Also known as wildcards or globs.

man bash then type /Pathname Expansion<Enter>.

Or better yet, if info is installed, info bash will get you exactly the same information as the link in your question.

You can drill down to the section manually, or get there directly by running:

info bash 'Basic Shell Features' 'Shell Expansions' 'Filename Expansion' 'Pattern Matching'

a final tip

You can try searching for man pages by running:

man -k <search term>

For example:

$ man -k regex
re_comp (3)          - BSD regex functions
re_exec (3)          - BSD regex functions
regcomp (3)          - POSIX regex functions
regerror (3)         - POSIX regex functions
regex (3)            - POSIX regex functions
regex (7)            - POSIX.2 regular expressions
regexec (3)          - POSIX regex functions
regexp_table (5)     - format of Postfix regular expression tables
regfree (3)          - POSIX regex functions
like image 62
Mikel Avatar answered Oct 25 '25 14:10

Mikel


Would man grep do?

Or you could always, you know, actually learn regexp.

like image 26
Matti Virkkunen Avatar answered Oct 25 '25 16:10

Matti Virkkunen