Regular Expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Buddy

    #1

    Regular Expression

    Can someone please show me how to create a regular expression to do the
    following

    My text is set to
    [vbl] MyColumn{1, 100} Test

    I want a regular expression that sets the text to the following
    [vbl] testMyColumn{1, 100}Test

    Basically I want the regular expression to add the word test infront of the
    word MyColumn and also remove 4 spaces after } and the word Test.

    Thanks


  • Juan Gabriel Del Cid

    #2
    Re: Regular Expression

    > My text is set to[color=blue]
    > [vbl] MyColumn{1, 100} Test
    >
    > I want a regular expression that sets the text to the following
    > [vbl] testMyColumn{1, 100}Test[/color]

    The pattern is:

    string pattern = @"(\[vbl] )(MyColumn\{\d+ , \d+\})(\s+)(Tes t)";

    and you should use a MatchEvaluator that returns the propper string.

    Hope that helps,
    -JG


    Comment

    • Jeffrey Tan[MSFT]

      #3
      RE: Regular Expression


      Hi Buddy,

      I think you can do something like this:

      string str="[vbl] MyColumn{1, 100} Test";
      Regex rg1=new Regex("\\s{4}") ;
      string [] collection=rg1. Split(str);
      Regex rg2=new Regex("My");
      string new1=rg2.Replac e(collection[0],collection[1].ToLower());
      string new2=new1+colle ction[1];
      MessageBox.Show (new2);

      Hope this helps,
      Jeffrey Tan
      Microsoft Online Partner Support
      Get Secure! - www.microsoft.com/security
      This posting is provided "as is" with no warranties and confers no rights.

      --------------------
      | From: "Buddy" <Buddy@onlineho me.com>
      | Subject: Regular Expression
      | Date: Fri, 24 Oct 2003 23:18:50 +0100
      | Lines: 15
      | X-Priority: 3
      | X-MSMail-Priority: Normal
      | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
      | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
      | Message-ID: <uwgiMznmDHA.97 6@tk2msftngp13. phx.gbl>
      | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
      | NNTP-Posting-Host: 81-1-69-6.homechoice.co .uk 81.1.69.6
      | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
      | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1939 40
      | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
      |
      | Can someone please show me how to create a regular expression to do the
      | following
      |
      | My text is set to
      | [vbl] MyColumn{1, 100} Test
      |
      | I want a regular expression that sets the text to the following
      | [vbl] testMyColumn{1, 100}Test
      |
      | Basically I want the regular expression to add the word test infront of
      the
      | word MyColumn and also remove 4 spaces after } and the word Test.
      |
      | Thanks
      |
      |
      |

      Comment

      • Buddy@Onlinehome.com

        #4
        RE: Regular Expression

        Thanks for the reply Jeffrey, I only want to know what's
        the Regular Expression parttern?

        Thanks,
        [color=blue]
        >-----Original Message-----
        >
        >Hi Buddy,
        >
        >I think you can do something like this:
        >
        >string str="[vbl] MyColumn{1, 100} Test";
        >Regex rg1=new Regex("\\s{4}") ;
        >string [] collection=rg1. Split(str);
        >Regex rg2=new Regex("My");
        >string new1=rg2.Replac e(collection[0],collection[/color]
        [1].ToLower());[color=blue]
        >string new2=new1+colle ction[1];
        >MessageBox.Sho w(new2);
        >
        >Hope this helps,
        >Jeffrey Tan
        >Microsoft Online Partner Support
        >Get Secure! - www.microsoft.com/security
        >This posting is provided "as is" with no warranties and[/color]
        confers no rights.[color=blue]
        >
        >--------------------
        >| From: "Buddy" <Buddy@onlineho me.com>
        >| Subject: Regular Expression
        >| Date: Fri, 24 Oct 2003 23:18:50 +0100
        >| Lines: 15
        >| X-Priority: 3
        >| X-MSMail-Priority: Normal
        >| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
        >| X-MimeOLE: Produced By Microsoft MimeOLE[/color]
        V6.00.2800.1165[color=blue]
        >| Message-ID: <uwgiMznmDHA.97 6@tk2msftngp13. phx.gbl>
        >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
        >| NNTP-Posting-Host: 81-1-69-6.homechoice.co .uk 81.1.69.6
        >| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl![/color]
        tk2msftngp13.ph x.gbl[color=blue]
        >| Xref: cpmsftngxa06.ph x.gbl[/color]
        microsoft.publi c.dotnet.langua ges.csharp:1939 40[color=blue]
        >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
        >|
        >| Can someone please show me how to create a regular[/color]
        expression to do the[color=blue]
        >| following
        >|
        >| My text is set to
        >| [vbl] MyColumn{1, 100} Test
        >|
        >| I want a regular expression that sets the text to the[/color]
        following[color=blue]
        >| [vbl] testMyColumn{1, 100}Test
        >|
        >| Basically I want the regular expression to add the[/color]
        word test infront of[color=blue]
        >the
        >| word MyColumn and also remove 4 spaces after } and the[/color]
        word Test.[color=blue]
        >|
        >| Thanks
        >|
        >|
        >|
        >
        >.
        >[/color]

        Comment

        • Jeffrey Tan[MSFT]

          #5
          RE: Regular Expression


          Hi Buddy,

          Net Framework provides System.Text.Reg ularExpressions namespace for us to
          work with Regular Expression.
          You can get a simple general introduction of ".NET Framework Regular
          Expressions" at the link below:
          http://msdn.microsoft.com/library/de...us/cpguide/htm
          l/cpconcomregular expressions.asp

          But if you want to get a detailed reference of it, you can refer to the
          JScript .NET's "Regular Expression Syntax" section, link:
          http://msdn.microsoft.com/library/de...us/jscript7/ht
          ml/jsreconbackrefe rences.asp

          Finally, there is a web site special for Regular Expression, you can get a
          tutorial from it at:
          This tutorial teaches you how to create your own regular expressions, starting with the most basic regex concepts and ending with the most advanced and specialized capabilities.


          If I misunderstand your meanning, please feel free to tell me.

          Best regards,
          Jeffrey Tan
          Microsoft Online Partner Support
          Get Secure! - www.microsoft.com/security
          This posting is provided "as is" with no warranties and confers no rights.

          --------------------
          | Content-Class: urn:content-classes:message
          | From: "Buddy@Onlineho me.com" <anonymous@disc ussions.microso ft.com>
          | Sender: "Buddy@Onlineho me.com" <anonymous@disc ussions.microso ft.com>
          | References: <uwgiMznmDHA.97 6@tk2msftngp13. phx.gbl>
          <sSoLHZqmDHA.72 4@cpmsftngxa06. phx.gbl>
          | Subject: RE: Regular Expression
          | Date: Sat, 25 Oct 2003 05:30:30 -0700
          | Lines: 70
          | Message-ID: <025701c39af3$c 6f5e500$a001280 a@phx.gbl>
          | MIME-Version: 1.0
          | Content-Type: text/plain;
          | charset="iso-8859-1"
          | Content-Transfer-Encoding: 7bit
          | X-Newsreader: Microsoft CDO for Windows 2000
          | Thread-Index: AcOa88b1uu7kg/nXT9Oyh6bxrarHf Q==
          | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
          | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | Path: cpmsftngxa06.ph x.gbl
          | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1940 05
          | NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
          | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          |
          | Thanks for the reply Jeffrey, I only want to know what's
          | the Regular Expression parttern?
          |
          | Thanks,
          |
          | >-----Original Message-----
          | >
          | >Hi Buddy,
          | >
          | >I think you can do something like this:
          | >
          | >string str="[vbl] MyColumn{1, 100} Test";
          | >Regex rg1=new Regex("\\s{4}") ;
          | >string [] collection=rg1. Split(str);
          | >Regex rg2=new Regex("My");
          | >string new1=rg2.Replac e(collection[0],collection
          | [1].ToLower());
          | >string new2=new1+colle ction[1];
          | >MessageBox.Sho w(new2);
          | >
          | >Hope this helps,
          | >Jeffrey Tan
          | >Microsoft Online Partner Support
          | >Get Secure! - www.microsoft.com/security
          | >This posting is provided "as is" with no warranties and
          | confers no rights.
          | >
          | >--------------------
          | >| From: "Buddy" <Buddy@onlineho me.com>
          | >| Subject: Regular Expression
          | >| Date: Fri, 24 Oct 2003 23:18:50 +0100
          | >| Lines: 15
          | >| X-Priority: 3
          | >| X-MSMail-Priority: Normal
          | >| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
          | >| X-MimeOLE: Produced By Microsoft MimeOLE
          | V6.00.2800.1165
          | >| Message-ID: <uwgiMznmDHA.97 6@tk2msftngp13. phx.gbl>
          | >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | >| NNTP-Posting-Host: 81-1-69-6.homechoice.co .uk 81.1.69.6
          | >| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!
          | tk2msftngp13.ph x.gbl
          | >| Xref: cpmsftngxa06.ph x.gbl
          | microsoft.publi c.dotnet.langua ges.csharp:1939 40
          | >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          | >|
          | >| Can someone please show me how to create a regular
          | expression to do the
          | >| following
          | >|
          | >| My text is set to
          | >| [vbl] MyColumn{1, 100} Test
          | >|
          | >| I want a regular expression that sets the text to the
          | following
          | >| [vbl] testMyColumn{1, 100}Test
          | >|
          | >| Basically I want the regular expression to add the
          | word test infront of
          | >the
          | >| word MyColumn and also remove 4 spaces after } and the
          | word Test.
          | >|
          | >| Thanks
          | >|
          | >|
          | >|
          | >
          | >.
          | >
          |

          Comment

          Working...