{"id":13,"date":"2012-07-11T19:54:33","date_gmt":"2012-07-11T19:54:33","guid":{"rendered":"http:\/\/netpurists.com\/blogs\/?p=13"},"modified":"2012-07-11T19:56:26","modified_gmt":"2012-07-11T19:56:26","slug":"pattern-search-in-vs-net-2010-2","status":"publish","type":"post","link":"http:\/\/netpurists.com\/blogs\/?p=13","title":{"rendered":"Pattern Search in VS.Net 2010"},"content":{"rendered":"<p>Recently I came across a fresher recently recruited in my company doing a boring and repetitive work of Find and Replace, doing it manually. He was searching for a particular keyword in the code and replacing a couple of line with the new piece of code. He was not using the VS.Net\u2019s Find and Replace box because he needed to search for a Pattern and replace it with another pattern. He was not able to find a better and more accurate way of doing the same. So I thought of helping him and others who find Pattern search complicated by writing this blog and showing the power of Regex Patterns.<\/p>\n<p>So here we go with this example:<\/p>\n<p>Let\u2019s say we want to replace the \u2018Sample Code\u2019 Pattern with the \u2018Replace with\u2019 Pattern<\/p>\n<p><strong>Sample Code:<\/strong><\/p>\n<p><span style=\"color: #0000ff\">Select Case<\/span> etime<\/p>\n<p><span style=\"color: #0000ff\">Case<\/span> <span style=\"color: #33cccc\">EnumECEnt.EnmDisplayMessageType<\/span>.Alert<\/p>\n<p><strong>Replace with:<\/strong><\/p>\n<p><span style=\"color: #0000ff\">Select Case<\/span> enmtime<\/p>\n<p>Case <span style=\"color: #33cccc\">EnumECEnt.EnmDisplayMessageType<\/span>.Warning<\/p>\n<p>We have this common piece of code in lots of classes. I now need to change this. I will open the Find and Replace window and use its Regular Expression option. Below is the screenshot:<\/p>\n<p><a href=\"http:\/\/netpurists.com\/blogs\/wp-content\/uploads\/2012\/07\/Find-and-Replace2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-15\" src=\"http:\/\/netpurists.com\/blogs\/wp-content\/uploads\/2012\/07\/Find-and-Replace2-300x247.png\" alt=\"\" width=\"300\" height=\"247\" srcset=\"http:\/\/netpurists.com\/blogs\/wp-content\/uploads\/2012\/07\/Find-and-Replace2-300x247.png 300w, http:\/\/netpurists.com\/blogs\/wp-content\/uploads\/2012\/07\/Find-and-Replace2-1024x845.png 1024w, http:\/\/netpurists.com\/blogs\/wp-content\/uploads\/2012\/07\/Find-and-Replace2-363x300.png 363w, http:\/\/netpurists.com\/blogs\/wp-content\/uploads\/2012\/07\/Find-and-Replace2.png 1560w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Enter the relevant text in Find what and Replace with Text boxes as shown above.<\/p>\n<p>We can then search and replace as usually.<\/p>\n<p><strong>How does this work?<\/strong><\/p>\n<p>If you notice the text in Find what: box, the lines that we are searching for starts with a \u2018\\\u2019<\/p>\n<p><tt><strong>\\<\/strong><\/tt><strong>\u00a0<\/strong><strong>(backslash)<\/strong>\u00a0in Regex means match all characters after this. It even suppresses special Regex special characters like &#8211; <strong>[\\^$.|?*+(){}<\/strong><\/p>\n<p>Since we are looking for multi line texts we need to look for Line breaks. This is done by:<\/p>\n<p>\u201c<strong>\\n<\/strong>\u201d &#8211; Match a new line character<\/p>\n<p>So wasn&#8217;t this really simple? By using just a couple of Regex keywords we were able to do a complicated Find and Replace which could have required tedious manual effort.<\/p>\n<p>I can be reached at <a href=\"mailto:hsoni@netpurist.com\">hsoni@netpurists.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I came across a fresher recently recruited in my company doing a boring and repetitive work of Find and Replace, doing it manually. He was searching for a particular keyword in the code and replacing a couple of line &hellip; <a href=\"http:\/\/netpurists.com\/blogs\/?p=13\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-vs-net-2010"],"_links":{"self":[{"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":4,"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":19,"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/19"}],"wp:attachment":[{"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/netpurists.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}