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. C#
  4. Fairly simple Regex question...

Fairly simple Regex question...

Scheduled Pinned Locked Moved C#
regexhelptutorialquestion
4 Posts 3 Posters 0 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.
  • R Offline
    R Offline
    rvp717y
    wrote on last edited by
    #1

    Hi there. I'm getting a headache finding a regular expression to determine if the char that I've just read in is a word char (\w) or a valid form of punctuation (not sure how to best describe this in regex terms). Essentailly I'm in a loop reading char by char and wanting to go do "something else" at the end of each word - unless the word is follwed by a semicolon or a comma or so-on. In this case I want to loop agin to include the punctuation char in the word and then go off and do the "something else". I have the "word char" bit so far: Regex reg = new Regex("\\w", RegexOptions.IgnoreCase|RegexOptions.Compiled); But I need to add the "or a punctuation char" bit to this. I tried to using a number constructs to add the but nothing is working out! Any help is greatly appreciated. Kind regards, John. _______ Your system must be restarted for these changes to take effect. This is not a drill.

    J 1 Reply Last reply
    0
    • R rvp717y

      Hi there. I'm getting a headache finding a regular expression to determine if the char that I've just read in is a word char (\w) or a valid form of punctuation (not sure how to best describe this in regex terms). Essentailly I'm in a loop reading char by char and wanting to go do "something else" at the end of each word - unless the word is follwed by a semicolon or a comma or so-on. In this case I want to loop agin to include the punctuation char in the word and then go off and do the "something else". I have the "word char" bit so far: Regex reg = new Regex("\\w", RegexOptions.IgnoreCase|RegexOptions.Compiled); But I need to add the "or a punctuation char" bit to this. I tried to using a number constructs to add the but nothing is working out! Any help is greatly appreciated. Kind regards, John. _______ Your system must be restarted for these changes to take effect. This is not a drill.

      J Offline
      J Offline
      Jim Conigliaro
      wrote on last edited by
      #2

      Use the OR operator (|) in your regular expression: \w|\.|:|;|\? If you haven't already, you may want to get a copy of Regex Coach. It's a free utility for designing and testing regular expressions.

      Jim Conigliaro jconigliaro@ieee.org
      http://www.jimconigliaro.com

      R 1 Reply Last reply
      0
      • J Jim Conigliaro

        Use the OR operator (|) in your regular expression: \w|\.|:|;|\? If you haven't already, you may want to get a copy of Regex Coach. It's a free utility for designing and testing regular expressions.

        Jim Conigliaro jconigliaro@ieee.org
        http://www.jimconigliaro.com

        R Offline
        R Offline
        rvp717y
        wrote on last edited by
        #3

        Jim, That worked a treat - many thanks. I wasn't sure about the syntax - most of the web pages I saw have very complex examples or only code for one specifi thing - not a combination of several. Once again, thanks for your response. John. PS: The smiley in the middle of the expression was interesting!

        G 1 Reply Last reply
        0
        • R rvp717y

          Jim, That worked a treat - many thanks. I wasn't sure about the syntax - most of the web pages I saw have very complex examples or only code for one specifi thing - not a combination of several. Once again, thanks for your response. John. PS: The smiley in the middle of the expression was interesting!

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Most examples are more complex because they use regular expression to match the entire strings, not just to identify single characters. You should consider using the regular expression for what you are doing, instead of looping through the characters.

          --- b { font-weight: normal; }

          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