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. RegEx help for a RegEx Newb

RegEx help for a RegEx Newb

Scheduled Pinned Locked Moved C#
regextutorialcsharphelpquestion
8 Posts 6 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.
  • F Offline
    F Offline
    flipdoubt
    wrote on last edited by
    #1

    Can someone help me write a regular expression that will return a string from the beginning of the input string up until a certain string is reached? I know how to do this without regular expressions, but I want to use a regular expression so users can modify the format later. Also, can someone recommend a good tutorial for using regular expressions to accomplish this kind of task using .NET? Thanks.

    C J E S 4 Replies Last reply
    0
    • F flipdoubt

      Can someone help me write a regular expression that will return a string from the beginning of the input string up until a certain string is reached? I know how to do this without regular expressions, but I want to use a regular expression so users can modify the format later. Also, can someone recommend a good tutorial for using regular expressions to accomplish this kind of task using .NET? Thanks.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      www.expresso.com, or search for Expresso on this site. It's a program that helps you build and test regex. Also, the regex book from O'Reiley is pretty awesome.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      F 1 Reply Last reply
      0
      • F flipdoubt

        Can someone help me write a regular expression that will return a string from the beginning of the input string up until a certain string is reached? I know how to do this without regular expressions, but I want to use a regular expression so users can modify the format later. Also, can someone recommend a good tutorial for using regular expressions to accomplish this kind of task using .NET? Thanks.

        J Offline
        J Offline
        Joseph Guadagno
        wrote on last edited by
        #3

        I use http://regexlib.com/CheatSheet.aspx for Regular Expressions. There is also a "free" application to test .NET Regular Expressions http://www.sellsbrothers.com/tools/default.aspx#regexd.

        Here are some of my articles. Hope this helps! Joseph Guadagno http://www.josephguadagno.net

        D 1 Reply Last reply
        0
        • C Christian Graus

          www.expresso.com, or search for Expresso on this site. It's a program that helps you build and test regex. Also, the regex book from O'Reiley is pretty awesome.

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          F Offline
          F Offline
          flipdoubt
          wrote on last edited by
          #4

          But there is RegEx in general and then there is .NET's flavor of RegEx. Are you recommending the O'Reilly book for .NET?

          C 1 Reply Last reply
          0
          • F flipdoubt

            Can someone help me write a regular expression that will return a string from the beginning of the input string up until a certain string is reached? I know how to do this without regular expressions, but I want to use a regular expression so users can modify the format later. Also, can someone recommend a good tutorial for using regular expressions to accomplish this kind of task using .NET? Thanks.

            E Offline
            E Offline
            ednrgc
            wrote on last edited by
            #5

            If I understand you correctly, it would be a simple case of creating a regex string of something like "^(?.*)"+ sMyTerminatorString. Then check the matches for mymatch (or whatever you name it).

            1 Reply Last reply
            0
            • J Joseph Guadagno

              I use http://regexlib.com/CheatSheet.aspx for Regular Expressions. There is also a "free" application to test .NET Regular Expressions http://www.sellsbrothers.com/tools/default.aspx#regexd.

              Here are some of my articles. Hope this helps! Joseph Guadagno http://www.josephguadagno.net

              D Offline
              D Offline
              DavidNohejl
              wrote on last edited by
              #6

              +1 for http://regexlib.com[^]


              [My Blog]
              "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - RĂ¼diger Klaehn
              "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

              1 Reply Last reply
              0
              • F flipdoubt

                But there is RegEx in general and then there is .NET's flavor of RegEx. Are you recommending the O'Reilly book for .NET?

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                The O'Reilly book covers the different flavours in depth.

                Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                1 Reply Last reply
                0
                • F flipdoubt

                  Can someone help me write a regular expression that will return a string from the beginning of the input string up until a certain string is reached? I know how to do this without regular expressions, but I want to use a regular expression so users can modify the format later. Also, can someone recommend a good tutorial for using regular expressions to accomplish this kind of task using .NET? Thanks.

                  S Offline
                  S Offline
                  Skippums
                  wrote on last edited by
                  #8

                  Look into RegexOptions.MultiLine to change whether "." matches newlines as well... myRegex = new Regex("^.*?(?=myStringThatDelimitsTheEndOfTheMatch)"); Match m = myRegex.Match(sampleString); if (m.Success) { m.Value; // this returns only the part of the match // that occured prior to your delimiting string }

                  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