regex, does not contain

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tfpx
    New Member
    • May 2009
    • 4

    regex, does not contain

    Hi Experts,

    Wasn't sure where to put this so I followed the posting rules. I'm looking for a regex that gives me the following results:

    Example 1:
    string = "randomtextrand omtexttotal15.1 9randomtextrand omtext"
    needed result: "total15.19 "

    (I managed to do this pretty well, now the one that gives me a problem:)

    Example 2:
    string = "randomtextrand textsubtotal15. 19randomtextran domtext"
    needed result: ""

    Thanks very much for your feedback.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Example 2:
    Code:
    string = "randomtextrandtextsubtotal15.19randomtextrandomte xt"
    needed result: ""
    What am I missing here? You need a way to get a null?

    Comment

    • tfpx
      New Member
      • May 2009
      • 4

      #3
      No. I need a regex that gives a match in the first example and doesn't match in the second example.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Based on what as the criteria?
        The only difference I see between example 1 and example 2 is the placement of a space within randomtext (randomte xt) and (randomtex t)

        If the text is going to be random, I don't see how it can be used as criteria

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          OH... Is it the difference between total15.19 and subtotal15.19 ??

          I wouldn't do it with regex,but that's me.

          Code:
          If (Mystring.Contains("Subtotal")) return string.Empty;
          else
          {
          // do your regex thing here
          }
          Just a tip... It helps the reader a lot if you point out the important things in your post especially when it is hidden inside some long string that is easy to gloss over.

          Originally posted by Plain text
          Example 1:
          string = "randomtextrand omtexttotal15.1 9randomtextrand omtex t"
          needed result: "total15.19 "

          (I managed to do this pretty well, now the one that gives me a problem:)

          Example 2:
          string = "randomtextrand textsubtotal15. 19randomtextran domte xt"
          needed result: ""
          Originally posted by Using BOLD tags
          Example 1:
          string = "randomtextrand omtexttotal15.19randomtext randomtex t"
          needed result: "total15.19 "

          (I managed to do this pretty well, now the one that gives me a problem:)

          Example 2:
          string = "randomtextrand textsubtotal15.19randomtext randomte xt"
          needed result: ""
          Originally posted by Using HIGHLIGHT tags
          Example 1:
          string = "randomtextrand omtexttotal15.19randomtext randomtex t"
          needed result: "total15.19 "

          (I managed to do this pretty well, now the one that gives me a problem:)

          Example 2:
          string = "randomtextrand textsubtotal15.19randomtext randomte xt"
          needed result: ""
          More on tags. They're cool. Check'em out.

          Comment

          • tfpx
            New Member
            • May 2009
            • 4

            #6
            My apologies, I should've give a bit more info. Indeed its the difference between subtotal and total. Isn't it possible to do with a regex?

            Comment

            • tfpx
              New Member
              • May 2009
              • 4

              #7
              Some more info: The string results from a ocr engine, in most cases it will contain a subtotal and a total. The correct regex would return the total and not the subtotal. With the script you're suggesting this wouldn't work.

              Isn't there a way to check what the position is of all the occurences of total in a string, and then check for each occurance if the word is preceded by "sub"?

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                Got me. I spent a day with RegEx to make some methods to confirm IP format and the like, but otherwise haven't used RegEx much.

                What code did you use to make the first Total part you say works fine?

                Comment

                • jrpetit
                  New Member
                  • May 2009
                  • 1

                  #9
                  Answer

                  Answer:

                  (subtotal\s*[\d.]+)|(total\s*[\d.]+)

                  Your code to check to see if sub group 2 is empty and ignore sub group 1.

                  Comment

                  Working...