You are not logged in.

#1 2010-04-25 12:52:16

fgr
Member
From: Italy
Registered: 2009-02-12
Posts: 20

About regular expression

I need to find a regular expression that matches words with three characters (and the first letter is upper). I don't know enough about regular expression for doing it myself. How can I do?

Offline

#2 2010-04-25 12:58:39

Cyrusm
Member
From: Bozeman, MT
Registered: 2007-11-15
Posts: 1,053

Re: About regular expression

take a look on google, this is a pretty basic regex.

http://www.regular-expressions.info/tutorial.html
http://www.amk.ca/python/howto/regex/
http://www.codeproject.com/KB/dotnet/regextutorial.aspx

that should be more than enough to get you started.

also, what language are you trying to make a regular expression for?  the syntax can be different from language to language.

Last edited by Cyrusm (2010-04-25 13:05:50)


Hofstadter's Law:
           It always takes longer than you expect, even when you take into account Hofstadter's Law.

Offline

#3 2010-04-25 13:00:25

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: About regular expression

Take a look at
http://www.grymoire.com/Unix/Regular.html#uh-9
and
http://www.grymoire.com/Unix/Regular.html#uh-13
and
http://www.grymoire.com/Unix/Regular.html#uh-8
echo 'you You Your' | sed 's/\<[[:upper:]][[:alpha:]]\{2\}\>/XXX/g'
you XXX Your

Offline

#4 2010-04-25 13:29:52

fgr
Member
From: Italy
Registered: 2009-02-12
Posts: 20

Re: About regular expression

Cyrusm wrote:

also, what language are you trying to make a regular expression for?  the syntax can be different from language to language.

for Python and grep

Thanks to all for replies.

EDIT: I've found this:

grep '\<[A-Za-z]\{3\}\>'

But it matches both capital and lower case. However, it's a good beginning point. :-)

Last edited by fgr (2010-04-25 14:00:30)

Offline

#5 2010-04-25 15:04:38

Rip-Rip
Member
Registered: 2008-11-09
Posts: 32

Re: About regular expression

fgr wrote:
Cyrusm wrote:

also, what language are you trying to make a regular expression for?  the syntax can be different from language to language.

for Python and grep

Thanks to all for replies.

EDIT: I've found this:

grep '\<[A-Za-z]\{3\}\>'

But it matches both capital and lower case. However, it's a good beginning point. :-)

try :

grep '\<[A-Z][a-z]\{2\}\>'

It will find all words of three letters, beginning with an uppercase character, and finishing with two lowercase characters.

Offline

#6 2010-04-25 15:54:09

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,294

Re: About regular expression

fgr wrote:
Cyrusm wrote:

also, what language are you trying to make a regular expression for?  the syntax can be different from language to language.

for Python and grep

When I first saw Cyrusm's post, I thought he meant natural languages.  I thought that an interesting point I had never considered.  Almost every language I ever encounter is based on the Latin alphabet (or simple variations on it).  I realized I had no concept of how to deal with Greek, Syrillic, Arabic, Korean, and Various Japanese and Chinese alphabets.

Then I saw fgr's response as to programming language's, at which point I wondered if I had missed the point.

Without intending to hijack the thread, How do RE's work for languages that read right to left, or that may be more symbolic in nature?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#7 2010-04-26 16:12:50

fgr
Member
From: Italy
Registered: 2009-02-12
Posts: 20

Re: About regular expression

Rip-Rip wrote:

[...]
try :

grep '\<[A-Z][a-z]\{2\}\>'

It will find all words of three letters, beginning with an uppercase character, and finishing with two lowercase characters.

it works fine, thanks.

Offline

#8 2010-04-26 16:24:06

Cyrusm
Member
From: Bozeman, MT
Registered: 2007-11-15
Posts: 1,053

Re: About regular expression

ewaller wrote:
fgr wrote:
Cyrusm wrote:

also, what language are you trying to make a regular expression for?  the syntax can be different from language to language.

for Python and grep

When I first saw Cyrusm's post, I thought he meant natural languages.  I thought that an interesting point I had never considered.  Almost every language I ever encounter is based on the Latin alphabet (or simple variations on it).  I realized I had no concept of how to deal with Greek, Syrillic, Arabic, Korean, and Various Japanese and Chinese alphabets.

Then I saw fgr's response as to programming language's, at which point I wondered if I had missed the point.

Without intending to hijack the thread, How do RE's work for languages that read right to left, or that may be more symbolic in nature?

hm. I never thought of it that way.  it might be something worth researching...


Hofstadter's Law:
           It always takes longer than you expect, even when you take into account Hofstadter's Law.

Offline

#9 2010-04-26 16:34:28

fgr
Member
From: Italy
Registered: 2009-02-12
Posts: 20

Re: About regular expression

ewaller wrote:
fgr wrote:
Cyrusm wrote:

also, what language are you trying to make a regular expression for?  the syntax can be different from language to language.

for Python and grep

When I first saw Cyrusm's post, I thought he meant natural languages.  I thought that an interesting point I had never considered.  Almost every language I ever encounter is based on the Latin alphabet (or simple variations on it).  I realized I had no concept of how to deal with Greek, Syrillic, Arabic, Korean, and Various Japanese and Chinese alphabets.
[...]

It's an interesting matter. But, we don't forget who makes international standards for any area of applicability is a western institution...

Last edited by fgr (2010-04-27 17:12:36)

Offline

Board footer

Powered by FluxBB