Regex Help

G

Guest

I want to match some elements with regular expression
-------------------------------------------------------------------------------
<word> <type.> <meaning> : <synonyms>
e.g. preeminent adj. having paramount rank, dignity, or importance : OUTSTANDING
-------------------------------------------------------------------------------
But, I have no idea about the pattern.


string pattern = @"(<Word>[a-z]{4,}\s)?(?<Type>(n|v|vt|vi|adj|adv|/)+\.)";
Regex r = new Regex(pattern);
Match m = r.Match(strLine);

wordName = m.Groups["Word"].Value;
type = m.Groups["Type"].Value;
meaning = m.Groups["Meaning"].Value;
synonyms = m.Groups["Synonyms"].Value;
 
G

Guest

Try:

(?<word>^\w*)\s*(?<type>\w*\.)(?<meaning>([^:][a-z ,])*)\s*:\s*(?<syn>.*$)

My regular expression also assumes that ":" delimits the meaning from the synonyms. I don't really like the expression for the backreference "meaning", but I will leave that as an exercise for the reader. :)

The above expression produced this:

word => preeminent
type => adj.
meaning => having paramount rank, dignity, or importance
syn => OUTSTANDING


HTH
~ Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top