15.1 (conspect) Regexp

Patterns

There are two types ways to work with them:

  1. Matching is testing if the whole string can be described by pattern.
  2. Searching is finding a substring that matches pattern.

An integer cannot be used for Patterns. So you can't request to show files consisting only of any number, you should classify it (for example its length=3).

Regular expressions

Why do we need regular expressions?

To filter from the strings such that match the query. We are not looking for the entire string exactly , but for the string that has the desired substring. Regular expressions do not allow describing arbitrary strings. Its difference is that the class and characters in it are separated. It can describe almost any possible pattern, not bound to context and having no internal parts dependence (e. g. «a if precedes by b» or «integer number, than that number of characters» can not be described).

grep-search for a substring in a text file.

grep August ycall / / - August Call in ycall.

grep '[7-9] ' ycal / / - highlighting digits from 7 to 9 in white

grep 'u. u' ycall / / - looking for where there is a substring from [u, < something>, u]. the return of August

grep command 'e*o' g ycall / / = > 'e, p*, o'. Here we look for , e e, r * (zero or more times), o

Line start marker: grep '^[0-9][0-9]*' ycall

End of line marker: grep '[0-9][0-9]*$' ycall

Search and replace

sed — stream editor.

Extended regexp and dialects

Disadvantages of traditional regexp: it's not easy to:

HSE/ProgrammingOS/15_Regexp/Cospect_en (последним исправлял пользователь VasilyKireenko 2020-03-20 20:11:14)