Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Interrupted list

Interrupted list

Scheduled Pinned Locked Moved Regular Expressions
regexhelptutorialquestion
5 Posts 3 Posters 14 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15245024
    wrote on last edited by
    #1

    Hi to all! My name is Dumitru, and I am a newbie to regex. My situation is that I studied some regex on my own, but I realized I have some lacks so I have to ask other people who really understand regex. An example of my target text: Abc. 2:5a; 24:51d, 53; 1:9b, 22-23c; 1:22-23, 9; 1:22-23, 24-25; Am example of my insufficient regex formula: ((((\d)?\w*(\.)?\s\d*:\d*)((-|: |,)?\s)?)(((-)?|(\d*))?(,)?(\s)?){5}) # Case 01. My formula does not match small letters, after and next to digits, as a, d, b, c # Case 02. My formula does not find ; # Case 03. When Replace I have to add Abc. after each ; and before the next series of digits, like this: Abc. 2:5a; Abc. 24:51d, 53; Abc. 1:9b, 22-23c; etc. Note: The small letter after and next to the digits, may or may not be there. And I need to find / match only those that are not at the start of a string, that is, only those that are in the middle or at the end of a string. I would really appreciate any help. Thank you!

    OriginalGriffO L 2 Replies Last reply
    0
    • M Member_15245024

      Hi to all! My name is Dumitru, and I am a newbie to regex. My situation is that I studied some regex on my own, but I realized I have some lacks so I have to ask other people who really understand regex. An example of my target text: Abc. 2:5a; 24:51d, 53; 1:9b, 22-23c; 1:22-23, 9; 1:22-23, 24-25; Am example of my insufficient regex formula: ((((\d)?\w*(\.)?\s\d*:\d*)((-|: |,)?\s)?)(((-)?|(\d*))?(,)?(\s)?){5}) # Case 01. My formula does not match small letters, after and next to digits, as a, d, b, c # Case 02. My formula does not find ; # Case 03. When Replace I have to add Abc. after each ; and before the next series of digits, like this: Abc. 2:5a; Abc. 24:51d, 53; Abc. 1:9b, 22-23c; etc. Note: The small letter after and next to the digits, may or may not be there. And I need to find / match only those that are not at the start of a string, that is, only those that are in the middle or at the end of a string. I would really appreciate any help. Thank you!

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Instead of saying "it doesn't do this", tell us what it is expected to, and what it actually does. So if you want it break out 5 matches delimited by semicolons, and within that split them into smaller matches, then tell us that - and show us examples of what output you want. Regexes can be a pain to read at best, and just showing us a "bad regex" and saying "it doesn't do this" Isn't really very helpful! And are you using a tool to help you design and test Regexes? If so, which one?

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      M 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Instead of saying "it doesn't do this", tell us what it is expected to, and what it actually does. So if you want it break out 5 matches delimited by semicolons, and within that split them into smaller matches, then tell us that - and show us examples of what output you want. Regexes can be a pain to read at best, and just showing us a "bad regex" and saying "it doesn't do this" Isn't really very helpful! And are you using a tool to help you design and test Regexes? If so, which one?

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        M Offline
        M Offline
        Member_15245024
        wrote on last edited by
        #3

        I am using Notepad++ Thank you for pointing that out, I was not aware and I have comply to the forum common rules. What is expected is: 1. a string like this to be matched: Abc 2:5a; 24:51d, 53; 1:9b, 22-23c; 1:22-23, 9; 1:22-23, 24-25; 2. this string should not be matched if it is found at the start of a line, that is, a new row; only in the middle o at the end of a row. 3. if in the middle or at the end of a string/row, it should match only if it starts with capital letter. E.g. Abc, not abc 4. After matching the Replacing I need is like this: Abc 2:5a; Abc 24:51d, 53; Abc 1:9b, 22-23c; Abc 1:22-23, 9; Abc 1:22-23, 24-25; I hope I was more clear this time. I welcome any perfecting, because reading regex is indeed pain enough. So, I should be very accurate. Thank you, sir! :thumbsup:

        OriginalGriffO 1 Reply Last reply
        0
        • M Member_15245024

          I am using Notepad++ Thank you for pointing that out, I was not aware and I have comply to the forum common rules. What is expected is: 1. a string like this to be matched: Abc 2:5a; 24:51d, 53; 1:9b, 22-23c; 1:22-23, 9; 1:22-23, 24-25; 2. this string should not be matched if it is found at the start of a line, that is, a new row; only in the middle o at the end of a row. 3. if in the middle or at the end of a string/row, it should match only if it starts with capital letter. E.g. Abc, not abc 4. After matching the Replacing I need is like this: Abc 2:5a; Abc 24:51d, 53; Abc 1:9b, 22-23c; Abc 1:22-23, 9; Abc 1:22-23, 24-25; I hope I was more clear this time. I welcome any perfecting, because reading regex is indeed pain enough. So, I should be very accurate. Thank you, sir! :thumbsup:

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          You're welcome - it's not "forum common rules", it's just common sense - we only get exactly what you type, so the more accurate your question, the better the answer. To be honest, I wouldn't faff too much with a regex - use it to extract the basics, and then use your presentation language string handling to break the rest up. You'll end up with much more readable code, and given the "vagueness" of your description, it's very likely that something will change or have been forgotten. It's a lot easier to maintain PL code than a complicated regex! :laugh: I'd also suggest that you get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • M Member_15245024

            Hi to all! My name is Dumitru, and I am a newbie to regex. My situation is that I studied some regex on my own, but I realized I have some lacks so I have to ask other people who really understand regex. An example of my target text: Abc. 2:5a; 24:51d, 53; 1:9b, 22-23c; 1:22-23, 9; 1:22-23, 24-25; Am example of my insufficient regex formula: ((((\d)?\w*(\.)?\s\d*:\d*)((-|: |,)?\s)?)(((-)?|(\d*))?(,)?(\s)?){5}) # Case 01. My formula does not match small letters, after and next to digits, as a, d, b, c # Case 02. My formula does not find ; # Case 03. When Replace I have to add Abc. after each ; and before the next series of digits, like this: Abc. 2:5a; Abc. 24:51d, 53; Abc. 1:9b, 22-23c; etc. Note: The small letter after and next to the digits, may or may not be there. And I need to find / match only those that are not at the start of a string, that is, only those that are in the middle or at the end of a string. I would really appreciate any help. Thank you!

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Greetings Dumitru, Im not expert because there seems to be many different flavors, so Im just guessing on this. But it does seem like each "semicolon-comma pair" could be represented by something like ... (\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, ) So depending on your flavor, since the sample has 4-1/2 pairs, you might have to type a VERY long string like...

            ^([\w]+\. )(\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, )(\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, )(\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, )(\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, \d{1,2}(?:[-:]\d{1,2}[a-z]?)?;)$

            With a replacement like... \1\2\1\3\4\1\5\6\1\7\8\1\9

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups