{"id":4810,"date":"2021-05-28T17:59:53","date_gmt":"2021-05-28T17:59:53","guid":{"rendered":"https:\/\/www.s-sols.com\/?post_type=doc&#038;p=4810"},"modified":"2026-03-30T13:57:45","modified_gmt":"2026-03-30T13:57:45","slug":"regexp-accel","status":"publish","type":"doc","link":"https:\/\/www.s-sols.com\/docs\/wordpress\/accelerator\/settings-accel\/regexp-accel","title":{"rendered":"Regular Expressions Accelerator for WordPress"},"content":{"rendered":"<p>\n  A <a href=\"https:\/\/en.wikipedia.org\/wiki\/Regular_expression\" rel=\"nofollow noopener\" target=\"_blank\">regular expression<\/a> is a powerful language to match text content by various patterns.\n<\/p>\n<p>\n  For an instance, we have the Amazon Advertising script inside our page that we want to delay loading:\n<\/p>\n<p><code class=\"p\">amzn_assoc_placement = \"adunit0\";<br \/>amzn_assoc_enable_interest_ads = \"true\";<br \/>amzn_assoc_tracking_id = \"baskingridgeh-20\";<\/code>\n<\/p>\n<p>\n  So, the pattern for detecting this script by its body may be:\n<\/p>\n<p><code class=\"p\">@(?:^|\\W)amzn_assoc_placement\\s*=\\s*[\\'\"][\\w\\-]+[\\'\"]@<\/code>\n<\/p>\n<p>\n  Another example \u2013 there is separated script:\n<\/p>\n<p><code class=\"p\">&lt;script src=\"\/dir\/abc.js\"&gt;<\/code>\n<\/p>\n<p>\n  So, we can match it by:\n<\/p>\n<p><code>@\/abc\\.js@<\/code> or <code>src:@\/abc\\.js@<\/code> if is needed to limit searching only in <code>src<\/code>  (see below).\n<\/p>\n<p>\n  And we can <a href=\"https:\/\/regex101.com\/\" rel=\"nofollow noopener\" target=\"_blank\"><strong>test and debug our patterns<\/strong><\/a> and look at the syntax.\n<\/p>\n<h2>\n  Special extensions<br \/>\n<\/h2>\n<h3>\n  Scope prefixes for styles and scripts<br \/>\n<\/h3>\n<p>\n  In exclusions in <a href=\".\/settings-styles-accel#not_critical\">styles<\/a> and <a href=\".\/settings-scripts-accel#non_critical\">scripts<\/a> we can limit the scope of matching, as body, ID or source URL by adding related prefixes:\n<\/p>\n<ul>\n<li><strong>src<\/strong>\n<p style=\"text-align:left\">\n      Matching with content of <code>src<\/code> attribute.\n    <\/p>\n<\/li>\n<li><strong>id<\/strong>\n<p style=\"text-align:left\">\n      Matching with content of<code> id<\/code> attribute.\n    <\/p>\n<\/li>\n<li><strong>body<\/strong>\n<p style=\"text-align:left\">\n      Matching with body content. Body is taked as from inline script (or style) as from by URL.\n    <\/p>\n<\/li>\n<\/ul>\n<p>\n  This prefixes can be combined, e.g. <code>src,body<\/code> or <code>id,src<\/code>, etc. E.g. <code>src,body:@abc@<\/code> will search matching <code>src<\/code> attribute and body with string <code>abc<\/code>.\n<\/p>\n<p>\n  Also, if no prefixes are defined then it means matching in all places. E.g. <code>id,src,body:@abc@<\/code> equals to <code>@abc@<\/code>.\n<\/p>\n<h3><a id=\"conditions\"><\/a>Conditions<br \/>\n<\/h3>\n<p>\n  Also, results of standard rerular expression matching can be compared by appending with <code>=<\/code> or <code>!=<\/code> and exact value (with logical \u2018&amp;\u2019 operator as well). E.g. <code>@Ab\\w\\wef$@ = Abcdef &amp; @\\Fed(\\w)b(\\w\\)$@ != ca<\/code>. Also, you can check the result for the empty value by prepending expression with <code>!<\/code>, for example,<span style=\"font-size:12pt\"> <\/span><code>!@Ab\\w\\wef$@<\/code>.\n<\/p>\n<h2>\n  Examples<br \/>\n<\/h2>\n<p>\n  Scripts with <code>id<\/code> starting with <code>myid-<\/code>:\n<\/p>\n<p><code class=\"p\">id:@^myid-@<\/code>\n<\/p>\n<p>\n  Only inlined scripts that contains <code>aaa<\/code>:\n<\/p>\n<p><code class=\"p\">!src:@.+@ &amp; body:@aaa@<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A regular expression is a powerful language to match text content by various patterns. For an instance, we have the Amazon Advertising script inside our page that we want to delay loading: amzn_assoc_placement = &#8220;adunit0&#8221;;amzn_assoc_enable_interest_ads = &#8220;true&#8221;;amzn_assoc_tracking_id = &#8220;baskingridgeh-20&#8243;; So, the pattern for detecting this script by its body may be: @(?:^|\\W)amzn_assoc_placement\\s*=\\s*[\\'&#8221;][\\w\\-]+[\\'&#8221;]@ Another example \u2013&#8230;<\/p>\n","protected":false},"author":18,"featured_media":0,"parent":4812,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"rank_math_lock_modified_date":false},"categories":[816],"tags":[],"class_list":["post-4810","doc","type-doc","status-publish","hentry","category-accelerator"],"_links":{"self":[{"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/doc\/4810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/doc"}],"about":[{"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/types\/doc"}],"author":[{"embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/comments?post=4810"}],"up":[{"embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/doc\/4812"}],"wp:attachment":[{"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/media?parent=4810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/categories?post=4810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/tags?post=4810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}