Hi Guys,
can anyone help me to write a regex function for the following string .So my string is

book_title='The Old Man and His Sons'
'The Old Man and His Sons'

now i want to extract just

The Old Man and His Sons

so far my code looks like this

 Match o = Regex.Match(item.text, "book_title='([A-Za-z0-9])'");

thanks a lot for all the help

Who knows what the title might contain, so capturing everything is a good idea. And a named group makes it easier to access the match.

using System;
using System.Text.RegularExpressions;

namespace Ed {
    public class Program {
        static void Main(string[] args) {
            string source =
                "contents=false\n" +
                "book_title='The Old Man and His Sons'\n" +
                "sections=[\n" +
                "'The Old Man and His Sons'\n" +

            Console.WriteLine(Regex.Match(source, "book_title='(?<TITLE>.*)'").Groups["TITLE"]);

can you help me actually understand how this regex function work.I dont wana copy paste.Can you actually explain what ?<Title..*)' actually means.

> can you help me actually understand how this regex function work
Ed used ".*" to capture any number of characters instead of "[A-Za-z0-9]" to capture one instance of an alphabet letter or digit. There is also a named group, the "?<TITLE>" part, to make it easier to find the matched substring. You can use an unnamed group and access the Groups collection by index, but it is less convenient to find the one you want because there are other matched groups aside from the one in parentheses.

Match m = Regex.Match(source, "book_title='(.*)'");

// See all available groups
foreach (var group in m.Groups)

// Get the substring group

This is a handy reference.

Thanks for all the help i just have one more question for you.right now i am reading all the files from a folder which works fine.What i want to do now is to read the specific file from a folder.How can i do that .The path of the file should be selected by dialog box.Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.