Google Answers Logo
View Question
 
Q: Help fixing Regular expression for .NET ( No Answer,   0 Comments )
Question  
Subject: Help fixing Regular expression for .NET
Category: Computers > Programming
Asked by: bobopico-ga
List Price: $25.00
Posted: 12 Aug 2006 09:25 PDT
Expires: 10 Sep 2006 23:59 PDT
Question ID: 755305
I am writing a regular expression in .NET that needs to ignore things
in quotes but find all other words in the string.  It should ignore
functions things followed by an open paren.  The following almost
works:

Regex(@"(?<!\G[^""]*""[^""]*)\b([a-zA-Z])(\w+)?\b(?!\()");

except when there are two quoted strings without a word in between. 
Here is the code sample:  In this example it should return only
fruits.  Any ideas how to fix the expression?  I need the expression
to work in all cases.

        private void button1_Click(object sender, EventArgs e)
        {
             Regex rx_var = new
Regex(@"(?<!\G[^""]*""[^""]*)\b([a-zA-Z])(\w+)?\b(?!\()");
             rx_var.Replace(@"Apple 10 banana ""peas"", ""carrots"".,
1noword sum( kiwi ""potato"" decode(sum(strawberry))", new
MatchEvaluator(translate_var));
        }

        public string translate_var(Match m)
        {
            string x = m.ToString();
            MessageBox.Show(m.ToString());
            return x;
        }
Answer  
There is no answer at this time.

The following answer was rejected by the asker (they reposted the question).
Subject: Re: Help fixing Regular expression for .NET
Answered By: theta-ga on 13 Aug 2006 01:55 PDT
Rated:1 out of 5 stars
 
Hi bobopico-ga,
   I rewrote the expression from scratch and came up with the following:

    Regex(@"\b[A-Za-z]+\b(?!\()\b(?!"")");

   The above gives the correct results for the test string you have provided.
   
   You can test this regex with other test strings, and post a request
for clarifications if anything needs to be modified.

   Hope this helps.

Regards,
theta-ga

Request for Answer Clarification by bobopico-ga on 13 Aug 2006 09:53 PDT
So the following string doesnt seem to work:

"Apple 10 banana ""peas corn"", ""carrots""., 1noword sum( kiwi
""potato"" decode(sum(strawberry))"

it returns peas although it is in a quoted string.  (the double quotes
are actually in C# translated to a single quote).

Rahul

Request for Answer Clarification by bobopico-ga on 13 Aug 2006 13:55 PDT
One additional clarification is the _ are accepted as part of a work
so AVG_COST should be returned as a word. The initial posted
expression does that correctly as well, but I think when it was
rewritten it no longer does that.

Clarification of Answer by theta-ga on 16 Aug 2006 22:25 PDT
Hi bobopico-ga,
   I'm sorry I was unable to respond earlier dues to some issues with
my Internet access. I will be posting the correct solution soon.
   My apologies for the delay.
Regards,
Theta-ga

Request for Answer Clarification by bobopico-ga on 18 Aug 2006 20:23 PDT
Thanks for the update, I had no idea how long to wait.  I will make
sure to send a note to adjust the rating once the right answer is
posted.  Thanks again for your time!
Reason this answer was rejected by bobopico-ga:
I am waiting on a response to repost this question.  I posted
clarification on why the provided solution did not work, but i have
not received an answer after 3 days or so.  I am losing time to get a
response, before i need to look into other avenues.
bobopico-ga rated this answer:1 out of 5 stars
I am still hopefully for a correct answer, but the above answer is
worse then my original solution.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy