l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
April 21: Google Glass
Next Installfest:
TBD
Latest News:
Mar. 18: Google Glass at LUGOD's April meeting
Page last updated:
2001 Dec 30 16:59

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
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.


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.