{"id":1229,"date":"2023-10-14T09:49:14","date_gmt":"2023-10-14T09:49:14","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=1229"},"modified":"2023-11-08T09:57:25","modified_gmt":"2023-11-08T09:57:25","slug":"error-preg_match-delimiter-must-not-be-alphanumeric-or-backslash","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/error-preg_match-delimiter-must-not-be-alphanumeric-or-backslash\/","title":{"rendered":"Error: preg_match(): Delimiter must not be alphanumeric or backslash"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-8-1024x49.png\" alt=\"\" class=\"wp-image-1230\" width=\"843\" height=\"40\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-8-1024x49.png 1024w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-8-300x14.png 300w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-8-768x37.png 768w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-8-1536x74.png 1536w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-8-850x41.png 850w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-8.png 1697w\" sizes=\"auto, (max-width: 843px) 100vw, 843px\" \/><\/figure>\n\n\n\n<p>This is my code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> foreach ($quote_bids as $line) {\r\n                preg_match(\"is_bid_approved=(\\d+)\", $line, $matches);\r\n                if (isset($matches&#91;1])) {\r\n                    $is_bid_approved_values&#91;] = intval($matches&#91;1]);\r\n                }\r\n            }\r\n            $value_counts = collect($is_bid_approved_values)->countBy();\r\n           \r\n         }<\/code><\/pre>\n\n\n\n<p><br>The error &#8220;preg_match(): Delimiter must not be alphanumeric or backslash&#8221; occurs because the regular expression you are using contains a delimiter that is not allowed. Delimiters are used to separate the regular expression pattern from the rest of the string. The allowed delimiters are any punctuation character that is not alphanumeric, such as forward slash (<code class=\"\">\/<\/code>), colon (<code class=\"\">:<\/code>), or pipe (<code class=\"\">|<\/code>).<\/p>\n\n\n\n<p>In your case, you are using the regular expression <code class=\"\">\"is_bid_approved=(\\d+)\"<\/code> to match a string that starts with <code class=\"\">\"is_bid_approved=\"<\/code>, followed by a digit, and ends with no additional characters. The delimiter you are using is the equals sign (<code class=\"\">=<\/code>). However, the equals sign is alphanumeric, which means it is not allowed as a delimiter.<\/p>\n\n\n\n<p>To fix this error, you can either change the delimiter to a non-alphanumeric character, or you can escape the equals sign so that it is not interpreted as a delimiter. For example, you could change the regular expression to <code class=\"\">\"is_bid_approved=\\(?\\d+\\)\"<\/code>. This would use a question mark (<code class=\"\">?<\/code>) as the delimiter, which is allowed.<br><br><strong>updated code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>foreach ($quote_bids as $line) {\r\n    preg_match(\"\/is_bid_approved=(\\d+)\/\", $line, $matches);\r\n    if (isset($matches&#91;1])) {\r\n        $is_bid_approved_values&#91;] = intval($matches&#91;1]);\r\n    }\r\n}\r\n$value_counts = collect($is_bid_approved_values)->countBy();\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is my code: The error &#8220;preg_match(): Delimiter must not be alphanumeric or backslash&#8221; occurs because the regular expression you are using contains a delimiter that is&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1229","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=1229"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1229\/revisions"}],"predecessor-version":[{"id":1231,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1229\/revisions\/1231"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=1229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=1229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=1229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}