locked
Match between two words

    Question

  • I want to match everything between ANY two word including these two word.

    These are the words and I want to include the parenthesis aswell:

    (hex)

    (str)

     

    Please help with this because I don't know how to sole this

    Thanks för all your help and supportSmile

    Mindraid from Sweden

    Friday, May 11, 2007 6:35 PM

Answers

  • to do that u need to match with this regex

     

    \(hex\).*?\(str\)

     

    and replace the match i.e text *** (hex)41303633343630383530202020(str)  ***

    with an empty str. The result will be

     

    serial number  A063460850

     

    don't forget to use SingleLine ON

    Friday, May 11, 2007 9:06 PM

All replies

  • your spec is vague, but this regex

     

    \([^)]*\).*?\([^)]*\)

     

    would match on both words in your input and everything in between them

     

    c# code for regex object: [watch RegexOptions.Singleline]

     

    //  using System.Text.RegularExpressions;

    /// <summary>
    ///  Regular expression built for C# on: Fri, May 11, 2007, 02:56:22 PM
    ///  Using Expresso Version: 2.1.2150, http://www.ultrapico.com
    /// 
    ///  A description of the regular expression:
    /// 
    ///  \([^)]*\).*?\([^)]*\)
    ///      (
    ///      Any character other than ), any number of repetitions
    ///      )
    ///      Any character, any number of repetitions, as few as possible
    ///      (
    ///      Any character other than ), any number of repetitions
    ///      )
    /// 
    /// 
    /// </summary>
    public static Regex regex = new Regex(
        @"\([^)]*\).*?\([^)]*\)",
        RegexOptions.IgnoreCase
        | RegexOptions.Singleline
        );

    Friday, May 11, 2007 6:56 PM
  • This doesn't require a regular expression.

     

    If want to check if full words match, just compare them.

     

    Adamus

    Friday, May 11, 2007 7:04 PM
  • What i meant was that i want to match everything in between the word.

    From: (hex) .......To: (str)

    Whatever is between these two words i want to match.

     

    Here is an exampel of what I want to do and here is what it looks like:

     

    ----------------------------- here is what it looks like---------------------------------

        serial number      (hex)41303633343630383530202020
                           (str)A063460850

    -----------------------------------------------------------------------------------------------

     

    -----------------------------here is how I want it to look like-----------------------

        serial number  A063460850

    -----------------------------------------------------------------------------------------------

     

    So basically I want to clean this "string" in csharp.

     

     

    Thanks for your help

    //Mindraid

    Friday, May 11, 2007 8:50 PM
  • to do that u need to match with this regex

     

    \(hex\).*?\(str\)

     

    and replace the match i.e text *** (hex)41303633343630383530202020(str)  ***

    with an empty str. The result will be

     

    serial number  A063460850

     

    don't forget to use SingleLine ON

    Friday, May 11, 2007 9:06 PM
  • Hi

    Thanks for your help

    This solved my problemSmile

     

    //Mindraid

    Saturday, May 12, 2007 5:56 AM