{"id":2788,"date":"2023-08-02T09:29:58","date_gmt":"2023-08-02T07:29:58","guid":{"rendered":"https:\/\/digitalia.culturanuova.net\/blog\/?p=2788"},"modified":"2023-08-13T13:44:13","modified_gmt":"2023-08-13T11:44:13","slug":"regex-find-and-replace-a-digit","status":"publish","type":"post","link":"https:\/\/digitalia.culturanuova.net\/blog\/?p=2788","title":{"rendered":"Regex find and replace a digit"},"content":{"rendered":"\n<p>To find only a single digit (such as &#8220;1&#8221;, or &#8220;2&#8221;) and replace (only) it, you have to add a plus after \\d.<\/p>\n\n\n\n<p>Something like:<\/p>\n\n\n\n<p>(\\d+)<\/p>\n\n\n\n<p>(to <strong>find<\/strong> it) and <\/p>\n\n\n\n<p>\\1<\/p>\n\n\n\n<p>to <strong>replace<\/strong> it.<\/p>\n\n\n\n<p>For example you have to add a new element to these lines<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1 some first text \n3 some other text\n8 other text<\/code><\/pre>\n\n\n\n<p>You can use this regex<\/p>\n\n\n\n<p><strong>find<\/strong>: <code>(\\d+)<\/code> <strong>replace<\/strong>: <code>\\n\\1<\/code><\/p>\n\n\n\n<p>as a result you will get<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n1 some first text \n\n3 some other text\n\n8 other text<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To find only a single digit (such as &#8220;1&#8221;, or &#8220;2&#8221;) and replace (only) it, you have to add a plus after \\d. Something like: (\\d+) (to find it) and \\1 to replace it. For example you have to add a new element to these lines You can use this regex find: (\\d+) replace: \\n\\1 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/digitalia.culturanuova.net\/blog\/?p=2788\" class=\"more-link\">Leggi tutto<span class=\"screen-reader-text\"> &#8220;Regex find and replace a digit&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[642,566],"tags":[820,819,227],"class_list":["post-2788","post","type-post","status-publish","format-standard","hentry","category-epub","category-webmaster","tag-digit","tag-findreplace","tag-regex"],"_links":{"self":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2788"}],"version-history":[{"count":1,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2788\/revisions"}],"predecessor-version":[{"id":2789,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2788\/revisions\/2789"}],"wp:attachment":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}