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. Regex to match exact word and dash symbol

Regex to match exact word and dash symbol

Scheduled Pinned Locked Moved Regular Expressions
regexquestion
10 Posts 3 Posters 21 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_15335022
    wrote on last edited by
    #1

    hi would any one have a regex that would match (aug -) or(july -) or (june -)without the brackets but would not match just (aug)or (july) or (june) So far i have \W*((?i)aug -(?-i))\W* but this also matches aug which i dont want thanks

    OriginalGriffO L 2 Replies Last reply
    0
    • M Member_15335022

      hi would any one have a regex that would match (aug -) or(july -) or (june -)without the brackets but would not match just (aug)or (july) or (june) So far i have \W*((?i)aug -(?-i))\W* but this also matches aug which i dont want thanks

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

      I tried your regex in Expresso, and it matches "hello aug -goodbye" but not "hello aug goodbye". So ... what are you talking about?

      "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

        I tried your regex in Expresso, and it matches "hello aug -goodbye" but not "hello aug goodbye". So ... what are you talking about?

        "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_15335022
        wrote on last edited by
        #3

        im using regex in placemint for placement of window and brousers if i title a folder aug placemint macthes it , but i only want match on aug -

        1 Reply Last reply
        0
        • M Member_15335022

          hi would any one have a regex that would match (aug -) or(july -) or (june -)without the brackets but would not match just (aug)or (july) or (june) So far i have \W*((?i)aug -(?-i))\W* but this also matches aug which i dont want thanks

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

          Im no ideas what should be captured, so Im guessing that it should include alternates like... \W*(?i)((?:aug|july|june)(?-i) -)\W* Except that both \W* are redundant since they allow 0-occurrences, so they dont alter any matched text. Its best to include samples to keep the experts from guessing, so I will try to save them some troubles... Capture 'aug' or 'July' or 'JUNE' as whole words if followed by: 1-space, 1-hyphen, 0-or-1 space, and a 1-or-2 digit word. .*\W(?i)(aug|july|june(?-i)) - ?\d{1,2}\W.* Capture 'aug -' or 'July -' or 'JUNE -' with the same conditions... .*\W(?i)((?:aug|july|june(?-i)) -) ?\d{1,2}\W.* Capture 'aug -##' or 'July - ##' or 'JUNE - ##' with the same conditions... .*\W(?i)((?:aug|july|june(?-i)) - ?\d{1,2})\W.* Capture 'aug -' or 'July -' or 'JUNE -' as whole words, but only if - is followed by a non-word character like %. This does seem the most unlikely, but Im trying to copy your original match, because no samples are being posted... .*\W(?i)((?:aug|july|june)(?-i) -)\W.* If none of these match properly, you should include samples of your text lines, and say what should be captured. There is many experts who is not even going to answer, without first seeing some samples.

          M 1 Reply Last reply
          0
          • L Lost User

            Im no ideas what should be captured, so Im guessing that it should include alternates like... \W*(?i)((?:aug|july|june)(?-i) -)\W* Except that both \W* are redundant since they allow 0-occurrences, so they dont alter any matched text. Its best to include samples to keep the experts from guessing, so I will try to save them some troubles... Capture 'aug' or 'July' or 'JUNE' as whole words if followed by: 1-space, 1-hyphen, 0-or-1 space, and a 1-or-2 digit word. .*\W(?i)(aug|july|june(?-i)) - ?\d{1,2}\W.* Capture 'aug -' or 'July -' or 'JUNE -' with the same conditions... .*\W(?i)((?:aug|july|june(?-i)) -) ?\d{1,2}\W.* Capture 'aug -##' or 'July - ##' or 'JUNE - ##' with the same conditions... .*\W(?i)((?:aug|july|june(?-i)) - ?\d{1,2})\W.* Capture 'aug -' or 'July -' or 'JUNE -' as whole words, but only if - is followed by a non-word character like %. This does seem the most unlikely, but Im trying to copy your original match, because no samples are being posted... .*\W(?i)((?:aug|july|june)(?-i) -)\W.* If none of these match properly, you should include samples of your text lines, and say what should be captured. There is many experts who is not even going to answer, without first seeing some samples.

            M Offline
            M Offline
            Member_15335022
            wrote on last edited by
            #5

            Thanks for trying to help me with this, im a complete novice with regex i am trying to capture 'aug -' or 'July -' or 'JUNE -' sentance 'the aug' = would not match sentance 'aug1' = would not match sentance 'aug -2' = would not match sentance 'aug -' = would match

            L 1 Reply Last reply
            0
            • M Member_15335022

              Thanks for trying to help me with this, im a complete novice with regex i am trying to capture 'aug -' or 'July -' or 'JUNE -' sentance 'the aug' = would not match sentance 'aug1' = would not match sentance 'aug -2' = would not match sentance 'aug -' = would match

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

              Im guessing that you posted 4 complete samples, and that 'sentance' means 1 whole line?... \b(?i)((?:aug|july|june)(?-i) -)$

              M 1 Reply Last reply
              0
              • L Lost User

                Im guessing that you posted 4 complete samples, and that 'sentance' means 1 whole line?... \b(?i)((?:aug|july|june)(?-i) -)$

                M Offline
                M Offline
                Member_15335022
                wrote on last edited by
                #7

                yes thanks sentance means 1 whole line, i tried \b(?i)((?:aug|july|june)(?-i) -)$ but its not matching anything

                L 1 Reply Last reply
                0
                • M Member_15335022

                  yes thanks sentance means 1 whole line, i tried \b(?i)((?:aug|july|june)(?-i) -)$ but its not matching anything

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

                  Its a PCRE regex to capture text just like your 4th-sample, so matching any lines that end like... aug - Maybe you're using something else?? Not using $1 or \1 for replace?? Not giving full samples??

                  M 1 Reply Last reply
                  0
                  • L Lost User

                    Its a PCRE regex to capture text just like your 4th-sample, so matching any lines that end like... aug - Maybe you're using something else?? Not using $1 or \1 for replace?? Not giving full samples??

                    M Offline
                    M Offline
                    Member_15335022
                    wrote on last edited by
                    #9

                    example i use \W*((?i)ALARM CLOCK(?-i))\W* so any window that says alarm clock is placed at same position on desktop

                    L 1 Reply Last reply
                    0
                    • M Member_15335022

                      example i use \W*((?i)ALARM CLOCK(?-i))\W* so any window that says alarm clock is placed at same position on desktop

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

                      Without full samples relating to your posted question, Im really afraid nobody is going to help you. This site shows how my regex matches what you said needs to matched. https://regex101.com/r/cH4Jrg/1 Feel free to experiment with it, if that's easier than trying to describe what should be matched.

                      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