[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Grep on dictionary words



2009/11/29 Andrew Sackville-West <andrew@farwestbilliards.com>:
> On Sun, Nov 29, 2009 at 01:22:15AM +0200, Dotan Cohen wrote:
>> > will get the ones that start with capital alphas. if you want initial
>> > caps *only* then:
>> >
>> > grep "^[A-Z][a-z]*$"
>> >
>> > would match those.
>> >
>>
>> Thanks. I meant that caps could only be at the beginning of a word,
>> not in the middle. Expanding your example, I figured that would be:
>> grep "^[A-Z]?[a-z]*$"  // note the question mark
>
>> >
>> > grep "^[A-Z][a-z]*$"
>
> that's what this does, I believe...
>

This means that only words that start with a caps are valid. I need
"can start with a caps, but caps can be nowhere else". I got that like
this:
grep "^[A-Za-z][a-z]*$"
However I think that there is a better way.

This is a good exercise. I am bettering my regex skills as I learn
what works and what doesn't.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il


Reply to: