0

My input string is:

"<!--<clientHtml>--><br><br><br><b>Job Title:</b> Test text
<br><b>JobId:</b> 56565-116503
<br><br><b>City:</b> San Diego
<br><b>State:</b> CA
<br><b>Zip Code:</b> 92108
<br><br><br><b>Description:</b> 
            We are recruiting for a Controller to oversee all accounting and finance for a growing manufacturing company.  We are looking for someone who is hands on full cycle accounting.  


<br><br>
<!--<apply>test/apply><email></email><OriginalFetchUrl>http:test.xml</OriginalFetchUrl><OriginalWrapUrl>http://test.html</OriginalWrapUrl></clientHtml>-->";

I need to extract following string using C#/Regular expressions:

1."We are recruiting for a Controller to oversee all accounting and finance for a growing manufacturing company. We are looking for someone who is hands on full cycle accounting."

I also want to get rid of the line: test/apply></email>http:test.xml</OriginalFetchUrl>http://test.html</OriginalWrapUrl></clientHtml>-->

Can I please get help with the code?

Thanks for reading.

3
  • I know, this is no homework - but this regex questions are very similar ... did you give it any try? Did you have a look at the 100th of regex questions here on SO? Do you have any informations so far about regex? When you get an answer, will you have to ask the next time again or learn anything? Commented Sep 22, 2009 at 20:27
  • @tanascius - You are not being very helpful or kind. What are you hoping to accomplish? Commented Sep 22, 2009 at 20:31
  • Well, I don't know, maybe I'd like to see some code or something he tried? It is not against Ed or his question ... but more about the regex questions in general ... they are always like: I have this, give me code that produces that ... maybe I should just remove regex from my favorite tags. Commented Sep 22, 2009 at 20:34

2 Answers 2

2

Try something like this:

Description:</b>([^<]+)

Here is an example of how to use it:

using System;
using System.Text.RegularExpressions;

class Example
{
    static void Main()
    {
        String str = @"<!--<clientHtml>--><br><br><br><b>Job Title:</b> Test text
            <br><b>JobId:</b> 56565-116503
            <br><br><b>City:</b> San Diego
            <br><b>State:</b> CA
            <br><b>Zip Code:</b> 92108
            <br><br><br><b>Description:</b> 
                    We are recruiting for a Controller to oversee all accounting and finance for a growing manufacturing company.  We are looking for someone who is hands on full cycle accounting.  


            <br><br>
            <!--<apply>test/apply><email></email><OriginalFetchUrl>http:test.xml</OriginalFetchUrl><OriginalWrapUrl>http://test.html</OriginalWrapUrl></clientHtml>-->";

        Regex expression = new Regex(@"Description:</b>([^<]+)",
            RegexOptions.Compiled |
            RegexOptions.CultureInvariant |
            RegexOptions.IgnoreCase);

        Match match = expression.Match(str);

        if (match.Success)
            Console.WriteLine(match.Groups[1].Value.Trim());
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks.How do use regular expression to achieve following: Input:start<!--abcd-->end Output shud be: start end
0

Try something like this: (I didn't test it.)

string result = "";
Match m = Regex.Match(line, @"^\<b\>\s*Description\s*\:\s*\<\/b\>\s*(?<result>.*?)\s*\<", RegexOptions.IgnoreCase);
if (m.Success) 
{
    result = m.Groups["result"].Value;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.