regex doesn't match expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • skneife@gmail.com

    regex doesn't match expression

    Hi,
    I have an input string :
    <NEW>g04 8/1 0<catset>pub=g0 4</catset>
    and I use this regex expresssion to match from <NEWto </catset>, I
    wrote:
    <NEW>.+?</catsetbut it doesn't work, no match !
    What is the good way ?
    Thanks.

    Sam

  • Mythran

    #2
    Re: regex doesn't match expression



    <skneife@gmail. comwrote in message
    news:b207a9a8-b26f-4496-84ac-2b63ed9e47de@59 g2000hsb.google groups.com...
    Hi,
    I have an input string :
    <NEW>g04 8/1 0<catset>pub=g0 4</catset>
    and I use this regex expresssion to match from <NEWto </catset>, I
    wrote:
    <NEW>.+?</catsetbut it doesn't work, no match !
    What is the good way ?
    Thanks.
    >
    Sam
    >
    Depends on if you want the contents (in between NEWand </) or match the
    tags as well? Do you want captures?

    Here are a couple of solutions:

    Solution #1: this is a full match of what you asked for....
    \<NEW\>.@\</catset\>

    Solution #2: this is a full match with 2 captures. If you would like to see
    the reason for this, use the Replace with text in the Quick Replace dialog:

    Find expression:
    \<NEW\>{.*}\<ca tset\>{.*}\</catset\>

    Replace with expression:
    NEW: "\1"\nCATSE T: "\2"

    Do either of these find expressions solve your problem?

    HTH,
    Mythran


    Comment

    • kodehoved

      #3
      Re: regex doesn't match expression

      On Jun 19, 12:37 am, "Mythran" <Myth...@commun ity.nospamwrote :
      <skne...@gmail. comwrote in message
      >
      news:b207a9a8-b26f-4496-84ac-2b63ed9e47de@59 g2000hsb.google groups.com...
      >
      Hi,
      I have an input string :
      <NEW>g04 8/1 0<catset>pub=g0 4</catset>
      and I use this regex expresssion to match from <NEWto </catset>, I
      wrote:
      <NEW>.+?</catsetbut it doesn't work, no match !
      What is the good way ?
      Thanks.
      >
      Sam
      >
      Depends on if you want the contents (in between NEWand </) or match the
      tags as well? Do you want captures?
      >
      Here are a couple of solutions:
      >
      Solution #1: this is a full match of what you asked for....
      \<NEW\>.@\</catset\>
      >
      Solution #2: this is a full match with 2 captures. If you would like to see
      the reason for this, use the Replace with text in the Quick Replace dialog:
      >
      Find expression:
      \<NEW\>{.*}\<ca tset\>{.*}\</catset\>
      >
      Replace with expression:
      NEW: "\1"\nCATSE T: "\2"
      >
      Do either of these find expressions solve your problem?
      >
      HTH,
      Mythran
      I'm not sure what the problem is. The following prints "found"

      string s = "<NEW>g04 8/1 0<catset>pub=g0 4</catset>";
      if (Regex.IsMatch( s, "<NEW>.+?</catset>")) {
      Console.WriteLi ne("found");
      }

      Brian

      Comment

      • skneife@gmail.com

        #4
        Re: regex doesn't match expression

        On 19 juin, 09:07, kodehoved <afk...@gmail.c omwrote:
        On Jun 19, 12:37 am, "Mythran" <Myth...@commun ity.nospamwrote :
        >
        >
        >
        <skne...@gmail. comwrote in message
        >
        news:b207a9a8-b26f-4496-84ac-2b63ed9e47de@59 g2000hsb.google groups.com...
        >
        Hi,
        I have an input string :
        <NEW>g04 8/1 0<catset>pub=g0 4</catset>
        and I use this regex expresssion to match from <NEWto </catset>, I
        wrote:
        <NEW>.+?</catsetbut it doesn't work, no match !
        What is the good way ?
        Thanks.
        >
        Sam
        >
        Depends on if you want the contents (in between NEWand </) or match the
        tags as well? Do you want captures?
        >
        Here are a couple of solutions:
        >
        Solution #1: this is a full match of what you asked for....
        \<NEW\>.@\</catset\>
        >
        Solution #2: this is a full match with 2 captures. If you would like to see
        the reason for this, use the Replace with text in the Quick Replace dialog:
        >
        Find expression:
        \<NEW\>{.*}\<ca tset\>{.*}\</catset\>
        >
        Replace with expression:
        NEW: "\1"\nCATSE T: "\2"
        >
        Do either of these find expressions solve your problem?
        >
        HTH,
        Mythran
        >
        I'm not sure what the problem is. The following prints "found"
        >
        string s = "<NEW>g04 8/1 0<catset>pub=g0 4</catset>";
        if (Regex.IsMatch( s, "<NEW>.+?</catset>")) {
        Console.WriteLi ne("found");
        }
        >
        Brian
        Yes Brian you are right, my sample code match the searched string.
        I was using a tool for testing and it was not work for a unknown
        reason.
        Thanks for help.
        Sam

        Comment

        Working...