Implement egrep in C++ ONLY, all other language is consider invalid. Only need t
ID: 3530889 • Letter: I
Question
Implement egrep in C++ ONLY, all other language is consider invalid. Only need to have the following functionality We implement the following features (where in each case a is any single character, and r and s are regular expressions): a - match the character a ra - match pattern r followed by character a r | s - match pattern r or pattern s r* - match 0 or more occurences of pattern r r+ - meaning match 1 or more occurences or pattern r (r) - match pattern r And if it doesn't work, I won't give u credit either.Explanation / Answer
grep, egrep, fgrep - print lines matching a pattern
grep[OPTIONS]PATTERN[FILE...]
grep[OPTIONS] [-ePATTERN|-fFILE] [FILE...]
grepsearches the named inputFILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the givenPATTERN. By default,grepprints the matching lines.
In addition, two variant programsegrepandfgrepare available.egrepis the same asgrep -E.fgrepis the same asgrep -F. Direct invocation as eitheregreporfgrepis deprecated, but is provided to allow historical applications that rely on them to run unmodified.
Generic Program Information
Matcher Selection
Matching Control
General Output Control
Output Line Prefix Control
Context Line Control
File and Directory Selection
Other Options
A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions, by using various operators to combine smaller expressions.
grepunderstands three different versions of regular expression syntax: "basic," "extended" and "perl." InGNUgrep, there is no difference in available functionality between basic and extended syntaxes. In other implementations, basic regular expressions are less powerful. The following description applies to extended regular expressions; differences for basic regular expressions are summarized afterwards. Perl regular expressions give additional functionality, and are documented inpcresyntax(3) andpcrepattern(3), but may not be available on every system.
The fundamental building blocks are the regular expressions that match a single character. Most characters, including all letters and digits, are regular expressions that match themselves. Any meta-character with special meaning may be quoted by preceding it with a backslash.
The period.matches any single character.
Character Classes and Bracket Expressions
Anchoring
The Backslash Character and Special Expressions
Repetition
Concatenation
Alternation
Precedence
Back References and Subexpressions
Basic vs Extended Regular Expressions
The behavior ofgrepis affected by the following environment variables.
The locale for categoryLC_foois specified by examining the three environment variablesLC_ALL,LC_foo,LANG, in that order. The first of these variables that is set specifies the locale. For example, ifLC_ALLis not set, butLC_MESSAGESis set topt_BR, then the Brazilian Portuguese locale is used for theLC_MESSAGEScategory. The C locale is used if none of these environment variables are set, if the locale catalog is not installed, or ifgrepwas not compiled with national language support (NLS).
SGR substring for whole selected lines (i.e., matching lines when the-vcommand-line option is omitted, or non-matching lines when-vis specified). If however the booleanrvcapability and the-vcommand-line option are both specified, it applies to context matching lines instead. The default is empty (i.e., the terminal's default color pair).
cx=
SGR substring for whole context lines (i.e., non-matching lines when the-vcommand-line option is omitted, or matching lines when-vis specified). If however the booleanrvcapability and the-vcommand-line option are both specified, it applies to selected non-matching lines instead. The default is empty (i.e., the terminal's default color pair).
rv
Boolean value that reverses (swaps) the meanings of thesl=andcx=capabilities when the-vcommand-line option is specified. The default is false (i.e., the capability is omitted).
SGR substring for matching non-empty text in any matching line (i.e., a selected line when the-vcommand-line option is omitted, or a context line when-vis specified). Setting this is equivalent to setting bothms=andmc=at once to the same value. The default is a bold red text foreground over the current line background.
SGR substring for matching non-empty text in a selected line. (This is only used when the-vcommand-line option is omitted.) The effect of thesl=(orcx=ifrv) capability remains active when this kicks in. The default is a bold red text foreground over the current line background.
SGR substring for matching non-empty text in a context line. (This is only used when the-vcommand-line option is specified.) The effect of thecx=(orsl=ifrv) capability remains active when this kicks in. The default is a bold red text foreground over the current line background.
SGR substring for file names prefixing any content line. The default is a magenta text foreground over the terminal's default background.
ln=32
SGR substring for line numbers prefixing any content line. The default is a green text foreground over the terminal's default background.
bn=32
SGR substring for byte offsets prefixing any content line. The default is a green text foreground over the terminal's default background.
se=36
SGR substring for separators that are inserted between selected line fields (:), between context line fields, (-), and between groups of adjacent lines when nonzero context is specified (--). The default is a cyan text foreground over the terminal's default background.
ne
Boolean value that prevents clearing to the end of line using Erase in Line (EL) to Right ([K) each time a colorized item ends. This is needed on terminals on which EL is not supported. It is otherwise useful on terminals for which theback_color_erase(bce) boolean terminfo capability does not apply, when the chosen highlight colors do not affect the background, or when EL is too slow or causes too much flicker. The default is false (i.e., the capability is omitted).
See the Select Graphic Rendition (SGR) section in the documentation of the text terminal that is used for permitted values and their meaning as character attributes. These substring values are integers in decimal representation and can be concatenated with semicolons.greptakes care of assembling the result into a complete SGR sequence ([...m). Common values to concatenate include1for bold,4for underline,5for blink,7for inverse,39for default foreground color,30to37for foreground colors,90to97for 16-color mode foreground colors,38;5;0to38;5;255for 88-color and 256-color modes foreground colors,49for default background color,40to47for background colors,100to107for 16-color mode background colors, and48;5;0to48;5;255for 88-color and 256-color modes background colors.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.