{"id":219,"date":"2010-11-10T19:02:56","date_gmt":"2010-11-10T13:32:56","guid":{"rendered":"http:\/\/vikku.info\/codesnippets\/?p=219"},"modified":"2010-11-10T19:06:04","modified_gmt":"2010-11-10T13:36:04","slug":"matching-newline-in-multiline-text-without-using-dot-but-with-an-alternate-char-class","status":"publish","type":"post","link":"http:\/\/vikku.info\/codesnippets\/regular-expression\/matching-newline-in-multiline-text-without-using-dot-but-with-an-alternate-char-class\/","title":{"rendered":"Matching newline in multiline text without using DOT but with an alternate char class"},"content":{"rendered":"<p>The Character class \\w matches any word character, and \\W matches anything that isn&#8217;t a word character.<\/p>\n<p>So, [\\w\\W] matches anything, including a newline<\/p>\n<p>for example removing c style comments<\/p>\n<pre lang=\"text\">\/\\*[\\w\\W]*?\\*\/<\/pre>\n<p>another example is getting all text within a div<\/p>\n<pre lang=\"html4strict\">\r\n<div class=\"\\&quot;validtext_erea\\&quot;\">([\\w\\W]*?)&lt;\\\/div&gt;<\/div><\/pre>\n<p>Usually we use it as (.*?) but this matches all characters except newline.<\/p>\n<p>So the alternate char class w is used to find all chars and non chars.<\/p>\n<p>The question mark is used to include laziness because the * chars is greedy.<\/p>\n<p><strong>Reference<\/strong><br \/>\n<a href=\"http:\/\/www.adobe.com\/devnet\/dreamweaver\/articles\/regular_expressions_pt2.html\">http:\/\/www.adobe.com\/devnet\/dreamweaver\/articles\/regular_expressions_pt2.html<\/a><br \/>\n<strong>See this for more modifiers<\/strong><br \/>\n<a href=\"http:\/\/www.regular-expressions.info\/modifiers.html\">http:\/\/www.regular-expressions.info\/modifiers.html<\/a><br \/>\n<strong>For a long time i have been looking for this<\/strong><br \/>\n<a href=\"http:\/\/www.regular-expressions.info\/dot.html\">http:\/\/www.regular-expressions.info\/dot.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Character class \\w matches any word character, and \\W matches anything that isn&#8217;t a word character. So, [\\w\\W] matches anything, including a newline for example removing c style comments \/\\*[\\w\\W]*?\\*\/ another example is getting all text within a div ([\\w\\W]*?)&lt;\\\/div&gt; Usually we use it as (.*?) but this matches all characters except newline. So [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[25],"tags":[],"_links":{"self":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/219"}],"collection":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":5,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":221,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/219\/revisions\/221"}],"wp:attachment":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}