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. How to define a regular expression?

How to define a regular expression?

Scheduled Pinned Locked Moved C#
questionphpdatabaseregexhelp
4 Posts 2 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.
  • M Offline
    M Offline
    mangrovecm
    wrote on last edited by
    #1

    Dear Experts, I have a file contains the content: I want to get : href="index.php?act=area_link&act2=article_detail&category_id=1&pro_id=3&category_sub_id=57&article_id=16823" How can i help me? Thank in advance vtkiet05

    C 1 Reply Last reply
    0
    • M mangrovecm

      Dear Experts, I have a file contains the content: I want to get : href="index.php?act=area_link&act2=article_detail&category_id=1&pro_id=3&category_sub_id=57&article_id=16823" How can i help me? Thank in advance vtkiet05

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

      It depends. Do you want to JUST search for that string ? You don't need regex for that, obviously. What bits are open to differ ? When you say 'get', what bits, if any, do you want to group ? www.expresso.com is an awesome tool for writing regex

      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 )

      M 1 Reply Last reply
      0
      • C Christian Graus

        It depends. Do you want to JUST search for that string ? You don't need regex for that, obviously. What bits are open to differ ? When you say 'get', what bits, if any, do you want to group ? www.expresso.com is an awesome tool for writing regex

        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 )

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

        Thank for your reply. I scanned the site and i know that that site contained those hyper links I have a exp: string exp = "[^\"]*)\"|(?<1>\\S+))"; this exp works fine and result is "

        M 1 Reply Last reply
        0
        • M mangrovecm

          Thank for your reply. I scanned the site and i know that that site contained those hyper links I have a exp: string exp = "[^\"]*)\"|(?<1>\\S+))"; this exp works fine and result is "

          M Offline
          M Offline
          mangrovecm
          wrote on last edited by
          #4

          Hi Christian, I fixed: Change the string exp = "[^\"]*)\"|(?<1>\\S+))" to string exp = "[^\"]*)\"|(?<1>\\S+)))"; and the result is "index.php?act=area_link&act2=article_detail&category_id=1&pro_id=3&category_sub_id=57&article_id=16823" Source code: string exp = "[^\"]*)\"|(?<1>\\S+)))"; // Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. string line = ""; using (StreamReader sr = new StreamReader("temp.txt")) { line = sr.ReadToEnd(); sr.Close(); } Regex regx = new Regex(exp, RegexOptions.IgnoreCase | RegexOptions.Compiled); Match m = regx.Match(line); while (m.Success) { string t = m.Groups[1].Value; m = m.NextMatch(); } (-,-) vtkiet05

          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