Please visit my new Web Site https://coderstechzone.com
In most of the times we need to make or create a regular expression to find matching patterns from a given string or a file. Many languages support this feature like Javascript and also Asp.net C#. Regular expresion makes our life easy. Few days ago i have done a dataminig project where i found that how much necessary the regular expression is. I understand its power and capability. The developer who wants to learn regular expression then first gather some knowledge on regular expression and then use this easy and simple tool to test the pattern matches.It will definitely increases your confidence as well as skills on Regular Expression. So the regular expression example in back & forth.
The output looks like:
Design the UI in the following way:
<table border="0"> <tr> <td>Regular Expression: </td><td><asp:TextBox ID="txtExp" runat="server" Width="200px"></asp:TextBox></td> </tr> <tr> <td>Contents: </td><td><asp:TextBox ID="txtContent" runat="server" Columns="40" TextMode="MultiLine" Rows="5"></asp:TextBox></td> </tr> <tr> <td>Result: </td><td><asp:TextBox ID="txtResult" runat="server" Width="200px"></asp:TextBox></td> </tr> <tr> <td></td><td><asp:Button ID="cmdExecute" runat="server" Text="Execute" OnClick="cmdExecute_Click" /></td> </tr> </table>Now under Execute button click event write the following server code:
protected void cmdExecute_Click(object sender, EventArgs e) { string content = txtContent.Text; string pattern = txtExp.Text; MatchCollection mc = Regex.Matches(content, pattern); string sWord = ""; if (mc.Count > 0) { for (int i = 0; i < mc.Count; i++) { if (sWord.Length == 0) sWord = mc[i].Value; else sWord =sWord+ ","+ mc[i].Value; } } txtResult.Text = sWord; }Hope now you can test regular expressions in many different ways.
0 comments:
I WOULD BE DELIGHTED TO HEAR FROM YOU