using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\bexon\s+(\d+)\b.*?\s+gene_id\s+""([^""]*)""";
string input = @"chr1 hg19_refFlat exon 44160380 44160565 0.000000 + . gene_id ""KDM4A""; transcript_id ""KDM4A"";
chr1 hg19_refFlat exon 19563636 19563732 0.000000 - . gene_id ""EMC1""; transcript_id ""EMC1"";
chr1 hg19_refFlat exon 52870219 52870551 0.000000 + . gene_id ""PRPF38A""; transcript_id ""PRPF38A"";
chr1 hg19_refFlat exon 53373540 53373626 0.000000 - . gene_id ""ECHDC2""; transcript_id ""ECHDC2_dup2"";
chr1 hg19_refFlat exon 11839859 11840067 0.000000 + . gene_id ""C1orf167""; transcript_id ""C1orf167"";
chr1 hg19_refFlat exon 29037032 29037154 0.000000 + . gene_id ""GMEB1""; transcript_id ""GMEB1"";
chr1 hg19_refFlat exon 103356007 103356060 0.000000 - . gene_id ""COL11A1""; transcript_id ""COL11A1"";";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx