• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

Help with Regular Expression

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
ironwill96
Asked:
ironwill96
  • 5
  • 2
1 Solution
 
ironwill96Author Commented:
Oh yeah,

This is using C# Regular Expression with Visual Studio 2005 and .Net Framework 2.0 if any of that matters..
0
 
ozoCommented:
(WATERMELON).*MATCH TEXT HERE(.*)
0
 
ironwill96Author Commented:
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
ironwill96Author Commented:
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
 
ozoCommented:
the (WATERMELON) will be returned in the first Groups and the (.*) will be returned in the secong Groups
0
 
ironwill96Author Commented:
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
 
ironwill96Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now