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