small Reg exp prob

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

    #1

    small Reg exp prob

    Hello

    I was wondering how to match car and the rest behind car using reg.exp?

    /car black bla bla bla

    so i can handle "car" and "black bla bla bla" seperately afterwards

    TIA
    /Lasse


  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: small Reg exp prob

    Hi Lasse,

    It would probably be

    ^(car)([^$]+)$

    Note: I don't really remember which of $ and ^ actually stands for the
    beginning of line and the end of line. So you may have to swap these
    characters to obtain a valid RegExp. My legend is:

    ^ stands for the beginning of line
    $ stands for the end of line

    Hope this helps.

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE


    "Lasse Edsvik" <lasse@nospam.c om> wrote in message
    news:OIZ3wqAiDH A.1684@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hello
    >
    > I was wondering how to match car and the rest behind car using reg.exp?
    >
    > /car black bla bla bla
    >
    > so i can handle "car" and "black bla bla bla" seperately afterwards
    >
    > TIA
    > /Lasse
    >
    >[/color]

    Comment

    • Lasse Edsvik

      #3
      Re: small Reg exp prob

      hmm not sure either, but "car" can be any length and not just "car"

      it's more like:

      / followed by a Word, then a space, then Word(s)




      "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
      in message news:utDsqyAiDH A.1952@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi Lasse,
      >
      > It would probably be
      >
      > ^(car)([^$]+)$
      >
      > Note: I don't really remember which of $ and ^ actually stands for the
      > beginning of line and the end of line. So you may have to swap these
      > characters to obtain a valid RegExp. My legend is:
      >
      > ^ stands for the beginning of line
      > $ stands for the end of line
      >
      > Hope this helps.
      >
      > --
      > Dmitriy Lapshin [C# / .NET MVP]
      > X-Unity Test Studio
      > http://x-unity.miik.com.ua/teststudio.aspx
      > Bring the power of unit testing to VS .NET IDE
      >
      >
      > "Lasse Edsvik" <lasse@nospam.c om> wrote in message
      > news:OIZ3wqAiDH A.1684@TK2MSFTN GP12.phx.gbl...[color=green]
      > > Hello
      > >
      > > I was wondering how to match car and the rest behind car using reg.exp?
      > >
      > > /car black bla bla bla
      > >
      > > so i can handle "car" and "black bla bla bla" seperately afterwards
      > >
      > > TIA
      > > /Lasse
      > >
      > >[/color]
      >[/color]


      Comment

      • Dmitriy Lapshin [C# / .NET MVP]

        #4
        Re: small Reg exp prob

        Then it would look like

        ^([a-zA-Z]+)\s(([a-zA-Z]+)|$)+

        You might also like to use the ExplicitCapture option to have meaningful
        pieces grouped. For example, the outer parenthes after \s are not a
        meaningful capture by themselves, only the inner ones are.

        --
        Dmitriy Lapshin [C# / .NET MVP]
        X-Unity Test Studio

        Bring the power of unit testing to VS .NET IDE

        "Lasse Edsvik" <lasse@nospam.c om> wrote in message
        news:%23T$CS3Ai DHA.2500@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > hmm not sure either, but "car" can be any length and not just "car"
        >
        > it's more like:
        >
        > / followed by a Word, then a space, then Word(s)
        >
        >
        >
        >
        > "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
        > in message news:utDsqyAiDH A.1952@TK2MSFTN GP10.phx.gbl...[color=green]
        > > Hi Lasse,
        > >
        > > It would probably be
        > >
        > > ^(car)([^$]+)$
        > >
        > > Note: I don't really remember which of $ and ^ actually stands for the
        > > beginning of line and the end of line. So you may have to swap these
        > > characters to obtain a valid RegExp. My legend is:
        > >
        > > ^ stands for the beginning of line
        > > $ stands for the end of line
        > >
        > > Hope this helps.
        > >
        > > --
        > > Dmitriy Lapshin [C# / .NET MVP]
        > > X-Unity Test Studio
        > > http://x-unity.miik.com.ua/teststudio.aspx
        > > Bring the power of unit testing to VS .NET IDE
        > >
        > >
        > > "Lasse Edsvik" <lasse@nospam.c om> wrote in message
        > > news:OIZ3wqAiDH A.1684@TK2MSFTN GP12.phx.gbl...[color=darkred]
        > > > Hello
        > > >
        > > > I was wondering how to match car and the rest behind car using[/color][/color][/color]
        reg.exp?[color=blue][color=green][color=darkred]
        > > >
        > > > /car black bla bla bla
        > > >
        > > > so i can handle "car" and "black bla bla bla" seperately afterwards
        > > >
        > > > TIA
        > > > /Lasse
        > > >
        > > >[/color]
        > >[/color]
        >
        >[/color]

        Comment

        • Lasse Edsvik

          #5
          Re: small Reg exp prob

          Dmitriy,

          hmm, but i pass that string and want to get out the 2 stringvalues for the
          first Word and then second variable Word(s)

          /Lasse


          "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
          in message news:eWoM6wBiDH A.3104@TK2MSFTN GP11.phx.gbl...[color=blue]
          > Then it would look like
          >
          > ^([a-zA-Z]+)\s(([a-zA-Z]+)|$)+
          >
          > You might also like to use the ExplicitCapture option to have meaningful
          > pieces grouped. For example, the outer parenthes after \s are not a
          > meaningful capture by themselves, only the inner ones are.
          >
          > --
          > Dmitriy Lapshin [C# / .NET MVP]
          > X-Unity Test Studio
          > http://x-unity.miik.com.ua/teststudio.aspx
          > Bring the power of unit testing to VS .NET IDE
          >
          > "Lasse Edsvik" <lasse@nospam.c om> wrote in message
          > news:%23T$CS3Ai DHA.2500@TK2MSF TNGP09.phx.gbl. ..[color=green]
          > > hmm not sure either, but "car" can be any length and not just "car"
          > >
          > > it's more like:
          > >
          > > / followed by a Word, then a space, then Word(s)
          > >
          > >
          > >
          > >
          > > "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om>[/color][/color]
          wrote[color=blue][color=green]
          > > in message news:utDsqyAiDH A.1952@TK2MSFTN GP10.phx.gbl...[color=darkred]
          > > > Hi Lasse,
          > > >
          > > > It would probably be
          > > >
          > > > ^(car)([^$]+)$
          > > >
          > > > Note: I don't really remember which of $ and ^ actually stands for the
          > > > beginning of line and the end of line. So you may have to swap these
          > > > characters to obtain a valid RegExp. My legend is:
          > > >
          > > > ^ stands for the beginning of line
          > > > $ stands for the end of line
          > > >
          > > > Hope this helps.
          > > >
          > > > --
          > > > Dmitriy Lapshin [C# / .NET MVP]
          > > > X-Unity Test Studio
          > > > http://x-unity.miik.com.ua/teststudio.aspx
          > > > Bring the power of unit testing to VS .NET IDE
          > > >
          > > >
          > > > "Lasse Edsvik" <lasse@nospam.c om> wrote in message
          > > > news:OIZ3wqAiDH A.1684@TK2MSFTN GP12.phx.gbl...
          > > > > Hello
          > > > >
          > > > > I was wondering how to match car and the rest behind car using[/color][/color]
          > reg.exp?[color=green][color=darkred]
          > > > >
          > > > > /car black bla bla bla
          > > > >
          > > > > so i can handle "car" and "black bla bla bla" seperately afterwards
          > > > >
          > > > > TIA
          > > > > /Lasse
          > > > >
          > > > >
          > > >[/color]
          > >
          > >[/color]
          >[/color]


          Comment

          Working...