?
Solved

Help with Regular Expression

Posted on 2007-08-01
7
Medium Priority
?
287 Views
Last Modified: 2010-04-15
Hey all,

I need help real quick with a regular expression i'm trying to get to work correctly.

The combination that I need to pick up would look like this in the text (replaced some of the numbers/text to make it generic): "WATERMELON some text here some text here 27 some text here MATCH TEXT HERE 250".  From that section I would want to pull out "WATERMELON MATCH TEXT HERE 250" or even better, "WATERMELON 250" if that is possible.

I've tried some various ideas such as [WATERMELON]\s*.*[MATCH]\s*[TEXT]\s*[HERE]\s*\d* but that doesn't match up at all.  I'm not sure how to search for whole words without doing something generic like "\w*" to represent the word.

Any help would be greatly appreciated!

Thanks,
Nathan
0
Comment
Question by:ironwill96
  • 5
  • 2
7 Comments
 
LVL 2

Author Comment

by:ironwill96
ID: 19613824
Oh yeah,

This is using C# Regular Expression with Visual Studio 2005 and .Net Framework 2.0 if any of that matters..
0
 
LVL 85

Accepted Solution

by:
ozo earned 1500 total points
ID: 19613830
(WATERMELON).*MATCH TEXT HERE(.*)
0
 
LVL 2

Author Comment

by:ironwill96
ID: 19613850
That will pull out from WATERMELON through 250 but I wanted it actually extracted as in my sample output of either "WATERMELON MATCH TEXT HERE 250" or "WATERMELON 250".  The numbers can be anything, the MATCH TEXT HERE is constant though and where WATERMELON is is also fixed (can be one of a list of things).

Thanks,
Nathan
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:ironwill96
ID: 19613868
Let me give a much clearer and more direct example.

"heading 90 degrees east, crossing a junction found on the south side at 14 mm, a total distance of 27 mm to the intersection"

In that example, what I need to pull out is "east 27 mm" or "east a total distance of 27 mm".  Either one will work for what i'm doing with CAD instructions.

Thanks,
Nathan
0
 
LVL 85

Expert Comment

by:ozo
ID: 19613893
the (WATERMELON) will be returned in the first Groups and the (.*) will be returned in the secong Groups
0
 
LVL 2

Author Comment

by:ironwill96
ID: 19613913
Yes it grabs the whole thing but doesn't pull out just the section I need.  Is that something that is not possible with RegEx?  I have a lot of other regular expressions in this project that work just fine, it is just this one that is stumping me.
0
 
LVL 2

Author Comment

by:ironwill96
ID: 19613963
Your answer is sort of correct for what I was originally asking so i'll accept it, but i'm going to repost and reword the question to be more clear to see if I can get what I want a little better.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question