regex help

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

    #1

    regex help

    I need to write a regex pattern that matches (somethingA|som ethingB) and
    replace it with text on the left side of |

    Input
    "(something ) something (somethingA|som ethingB) something
    (somethingC|som ethingD) (something) something"

    Output
    "(something ) something (somethingA) something (somethingC) (something)
    something"

    Thanks

    Tem

  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: regex help

    Tem wrote:
    I need to write a regex pattern that matches (somethingA|som ethingB)
    and replace it with text on the left side of |
    >
    Input
    "(something ) something (somethingA|som ethingB) something
    (somethingC|som ethingD) (something) something"
    >
    Output
    "(something ) something (somethingA) something (somethingC) (something)
    something"
    Try:

    string s = "(something ) something (somethingA|som ethingB) something
    (somethingC|som ethingD) (something) something";
    string s2 = Regex.Replace(s , @"(\([^\|\)]*)(\|[^\)]*)(\))", "$1$3");

    Arne

    Comment

    • Tem

      #3
      Re: regex help

      thanks arne

      "Arne Vajhøj" <arne@vajhoej.d kwrote in message
      news:4838b52c$0 $90271$14726298 @news.sunsite.d k...
      Tem wrote:
      >I need to write a regex pattern that matches (somethingA|som ethingB) and
      >replace it with text on the left side of |
      >>
      >Input
      >"(something ) something (somethingA|som ethingB) something
      >(somethingC|so methingD) (something) something"
      >>
      >Output
      >"(something ) something (somethingA) something (somethingC) (something)
      >something"
      >
      Try:
      >
      string s = "(something ) something (somethingA|som ethingB) something
      (somethingC|som ethingD) (something) something";
      string s2 = Regex.Replace(s , @"(\([^\|\)]*)(\|[^\)]*)(\))", "$1$3");
      >
      Arne

      Comment

      • Tem

        #4
        Re: regex help

        How can I modify this so that the replace string does have ()

        Input
        "(something ) something (somethingA|som ethingB) something
        (somethingC|som ethingD) (something) something"

        Output
        "(something ) something somethingA something somethingC (something)
        something"


        I tried to do it myself, but couldn't get it to work.


        "Arne Vajhøj" <arne@vajhoej.d kwrote in message
        news:4838b52c$0 $90271$14726298 @news.sunsite.d k...
        Tem wrote:
        >I need to write a regex pattern that matches (somethingA|som ethingB) and
        >replace it with text on the left side of |
        >>
        >Input
        >"(something ) something (somethingA|som ethingB) something
        >(somethingC|so methingD) (something) something"
        >>
        >Output
        >"(something ) something (somethingA) something (somethingC) (something)
        >something"
        >
        Try:
        >
        string s = "(something ) something (somethingA|som ethingB) something
        (somethingC|som ethingD) (something) something";
        string s2 = Regex.Replace(s , @"(\([^\|\)]*)(\|[^\)]*)(\))", "$1$3");
        >
        Arne

        Comment

        • Tem

          #5
          Re: regex help

          I got it. missed a \

          "Tem" <tem1232@yahoo. comwrote in message
          news:eC5aMgrxIH A.4952@TK2MSFTN GP05.phx.gbl...
          How can I modify this so that the replace string does have ()
          >
          Input
          "(something ) something (somethingA|som ethingB) something
          (somethingC|som ethingD) (something) something"
          >
          Output
          "(something ) something somethingA something somethingC (something)
          something"
          >
          >
          I tried to do it myself, but couldn't get it to work.
          >
          >
          "Arne Vajhøj" <arne@vajhoej.d kwrote in message
          news:4838b52c$0 $90271$14726298 @news.sunsite.d k...
          >Tem wrote:
          >>I need to write a regex pattern that matches (somethingA|som ethingB)
          >>and replace it with text on the left side of |
          >>>
          >>Input
          >>"(something ) something (somethingA|som ethingB) something
          >>(somethingC|s omethingD) (something) something"
          >>>
          >>Output
          >>"(something ) something (somethingA) something (somethingC) (something)
          >>something"
          >>
          >Try:
          >>
          >string s = "(something ) something (somethingA|som ethingB) something
          >(somethingC|so methingD) (something) something";
          >string s2 = Regex.Replace(s , @"(\([^\|\)]*)(\|[^\)]*)(\))", "$1$3");
          >>
          >Arne
          >

          Comment

          • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

            #6
            Re: regex help

            Tem wrote:
            How can I modify this so that the replace string does have ()
            >
            Input
            "(something ) something (somethingA|som ethingB) something
            (somethingC|som ethingD) (something) something"
            >
            Output
            "(something ) something somethingA something somethingC (something)
            something"
            >
            I tried to do it myself, but couldn't get it to work.
            You asked that question a couple of weeks ago and I
            replied back then.

            Arne

            Comment

            Working...