Re: [vox-tech] some excercise for you linux geek.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [vox-tech] some excercise for you linux geek.
I listed answers w/ explanations;
but I should point out that they are actually all completely wrong.
The backslashed-escaped characters {, }, (, and ) would all lose their
special meanings in a regex.
For these answers, then, I assumed the regex is specified in a SHELL
which requires these things to be backslashed. However, that still
doesn't work with a couple examples.
I did my best to use a "Do What I Mean, Not What I Say" approach to
the answers.
-Micah
On Thu, Dec 07, 2000 at 01:44:05PM -0800, Chan Yan Huang wrote:
> what will be matched by following regular expressions? and explain if you
> have time
>
> xx*
a string of one or more x's
>
> x\{1,5\}
a string of x's: at least one, and up to 5.
The {m,n} notation means at least <m> and no more than
<n> of the immediately preceeding character or group
>
> x\{5,\}
a string of 5 or more x's
When <n> is left out, but the comma is there, it is assumed to be infinity.
>
> x\{10\}
a string of exactly 10 x's.
When there is no comma following <m>, <m> and only <m> repitions are
matched.
>
> [0-9]\{3\}
a 3-digit number
The [] grouping contains a list of matchable values.
The - character is a shorthand whose value is all the
values between and including the characters immediately before and
after it.
>
> [0-9]\{1,3\}, [0-9]\{3\}
a number from 1 to 3 digits, followed by a comma, a space, and
a 3-digit number.
>
> ^\...
a period followed by any two characters (except possibly a newline).
Only matches the beginning of the string.
The ^ token, if at the beginning of a regex, matches the beginning
of a string.
The period matches any character, unless it is backslash-escaped.
>
> \([A-Za-z0-9]\{1,\}\)\1
Matches any alphanumeric sequence which repeats itself once immediately.
The \1 matches whatever was in the last set of parens.
>
> ^Begin$
Matches only if the entire string is "Begin"
The dollar sign, when placed at the end of a regex, matches the end
of the string.
>
> ^\(.\).*\1$
>
matches only if the entire string ends with the same character it
begins with.
|