{"id":1424,"date":"2015-04-28T06:51:41","date_gmt":"2015-04-28T06:51:41","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=1424"},"modified":"2015-08-06T12:18:53","modified_gmt":"2015-08-06T12:18:53","slug":"javascript-regex-match-for-string-game_1","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/javascript-regex-match-for-string-game_1\/","title":{"rendered":"Javascript regex match for string \u201cgame_1\u201d"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[1424]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>My <a href=\"http:\/\/stackoverflow.com\/questions\/6608223\/javascript-regex-match-for-string-game-1\">question<\/a> was:<\/p>\n<p>I just can&#8217;t get this thing to work in javascript. So, I have a text &#8220;game_1&#8221; without the quotes and now i want to get that number out of it and I tried this:<\/p>\n<pre class=\"lang:default decode:true\">var idText = \"game_1\";\r\nre = \/game_(.*?)\/;\r\nfound = idText.match(re);\r\n\r\nvar ajdi = found[1];\r\nalert( ajdi );<\/pre>\n<p>But it doesn&#8217;t work &#8211; please point out where am I going wrong.<\/p>\n<p style=\"color: #222222;\">\u00a0The answer, by <a href=\"http:\/\/stackoverflow.com\/users\/716007\/naltharial\">Naltharial<\/a>,\u00a0was:<\/p>\n<blockquote><p>If you&#8217;re only matching a number, you may want to try<\/p>\n<pre class=\"lang:default decode:true  \">\/game_([0-9]+)\/<\/pre>\n<p>as your regular expression. That will match <em>at least one<\/em> number, which seems to be what you need. You entered a regexp that allows for 0 characters (<code>*<\/code>) and let it select the shortest possible result (<code>?<\/code>), which may be a problem (and match you 0 characters), depending on the regex engine.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%).\u00a0In this category (stackoverflow)\u00a0of posts I will will be posting&hellip;<\/p>\n","protected":false},"author":1,"featured_media":609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1424","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=1424"}],"version-history":[{"count":2,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1424\/revisions"}],"predecessor-version":[{"id":1682,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1424\/revisions\/1682"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/609"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=1424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=1424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=1424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}