Regular Expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Sm9obg==?=

    #1

    Regular Expression

    Hi,

    I need to find the following and replace it using Regular Expression.

    The text between those two tags can be anything, printable or unprintable,
    and can be any length. Please help. Thanks.

    <Info>whateve r-include-unprintable-charasters</Info>
  • =?Utf-8?B?S0g=?=

    #2
    RE: Regular Expression

    What are unprintable characters?
    Anyways ... not a regex but you really don't need one for this:

    string str = "<Info>what ever-include-unprintable-charasters</Info>";

    int begin = str.IndexOf('>' );
    int end = str.LastIndexOf ('<');

    if (begin -1 && end -1)
    {
    begin += 1;
    end -= begin;
    str = str.Substring(b egin, end);
    }

    Console.WriteLi ne( str );


    HTH


    "John" wrote:
    Hi,
    >
    I need to find the following and replace it using Regular Expression.
    >
    The text between those two tags can be anything, printable or unprintable,
    and can be any length. Please help. Thanks.
    >
    <Info>whateve r-include-unprintable-charasters</Info>

    Comment

    • Obaum1

      #3
      Re: Regular Expression

      On Aug 14, 8:02 pm, John <J...@discussio ns.microsoft.co mwrote:
      Hi,
      >
      I need to find the following and replace it using Regular Expression.
      >
      The text between those two tags can be anything, printable or unprintable,
      and can be any length. Please help. Thanks.
      >
      <Info>whateve r-include-unprintable-charasters</Info>

      Hello

      string regex = @"<info>(?<Test >.*?)</info>";
      Regex r = new Regex(regex);

      MatchCollection mc = r.Matches( The src of the page or somting );
      foreach (Match m in mc)
      {
      string TestText = m.Result("${Tes t}");

      }

      In every iteration you will have what you nee in TestText
      .*? = To every thing
      [A-Za-z0-9-]+ letter and numbers

      Bast Regarts
      Ohav Baumgarten

      Comment

      Working...