Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
gmis

Test String

Code Generator

Generated Code

$re = '/<script*[^>]*>(.+?)<\/script[^>]*>|<!--*(.+?)-->|<style*[^>]*>(.+?)<\/style[^>]*>|<javascript*[^>]*>(.*?)<\/javascript[^>]*>|<(?:"[^"]*"[\'"]*|\'[^\']*\'[\'"]*|[^\'">])+>/mis'; $str = '<!DOCTYPE html> <html itemscope itemtype="http://schema.org/QAPage"> <head> <title>java - Regex to match single quotes being quoted by double-quotes - Stack Overflow</title> <link rel="shortcut icon" href="//cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d"> <link rel="apple-touch-icon image_src" href="//cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a"> <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml"> <meta name="twitter:card" content="summary"> <meta name="twitter:domain" content="stackoverflow.com"/> <meta property="og:type" content="website" /> <meta property="og:image" itemprop="image primaryImageOfPage" content="http://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded&a" /> <meta name="twitter:title" property="og:title" itemprop="title name" content="Regex to match single quotes being quoted by double-quotes" /> <meta name="twitter:description" property="og:description" itemprop="description" content="Here is a Regex I have been trying to make work: (?:&quot;[^&quot;]*&quot;[^&quot;]*)*?\\&quot;{1}([^&quot;]*?([&#39;]{1,})[^&quot;]*?)\\&quot; It is probably not the most clean nor the most effective way to achieve what I want to do, but I&#39;m " /> <meta property="og:url" content="http://stackoverflow.com/questions/36183788/regex-to-match-single-quotes-being-quoted-by-double-quotes"/> <link rel="canonical" href="http://stackoverflow.com/questions/36183788/regex-to-match-single-quotes-being-quoted-by-double-quotes" /> <javascript src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" />abc <javascript src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></javascript> <javascript src="//cdn.sstatic.net/Js/stub.en.js?v=c1341d3ea930"></javascript> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" />abc <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="//cdn.sstatic.net/Js/stub.en.js?v=c1341d3ea930"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/stackoverflow/all.css?v=3f4c51969762"> text goes here <link rel="alternate" type="application/atom+xml" title="Feed for question &#39;Regex to match single quotes being quoted by double-quotes&#39;" href="/feeds/question/36183788"> <meta name="twitter:app:country" content="US" /> <meta name="twitter:app:name:iphone" content="Stack Exchange iOS" /> <meta name="twitter:app:id:iphone" content="871299723" /> <meta name="twitter:app:url:iphone" content="se-zaphod://stackoverflow.com/questions/36183788/regex-to-match-single-quotes-being-quoted-by-double-quotes" /> <meta name="twitter:app:name:ipad" content="Stack Exchange iOS" /> <meta name="twitter:app:id:ipad" content="871299723" /> <meta name="twitter:app:url:ipad" content="se-zaphod://stackoverflow.com/questions/36183788/regex-to-match-single-quotes-being-quoted-by-double-quotes" /> <meta name="twitter:app:name:googleplay" content="Stack Exchange Android"> <meta name="twitter:app:url:googleplay" content="http://stackoverflow.com/questions/36183788/regex-to-match-single-quotes-being-quoted-by-double-quotes"> <meta name="twitter:app:id:googleplay" content="com.stackexchange.marvin"> <script> StackExchange.ready(function () { StackExchange.using("snippets", function () { StackExchange.snippets.initSnippetRenderer(); }); StackExchange.using("postValidation", function () { StackExchange.postValidation.initOnBlurAndSubmit($(\'#post-form\'), 2, \'answer\'); }); StackExchange.question.init({showAnswerHelp:true,totalCommentCount:5,shownCommentCount:5,highlightColor:\'#F4A83D\',backgroundColor:\'#FFF\',questionId:36183788}); styleCode(); StackExchange.realtime.subscribeToQuestion(\'1\', \'36183788\'); StackExchange.using("gps", function () { StackExchange.gps.trackOutboundClicks(\'#content\', \'.post-text\'); }); }); </script> <script> StackExchange.init({"locale":"en","stackAuthUrl":"https://stackauth.com","networkMetaHostname":"meta.stackexchange.com","serverTime":1462811219,"routeName":"Questions/Show","styleCode":true,"enableUserHovercards":true,"snippets":{"enabled":true,"domain":"stacksnippets.net"},"site":{"name":"Stack Overflow","description":"Q&A for professional and enthusiast programmers","isNoticesTabEnabled":true,"recaptchaPublicKey":"6LdchgIAAAAAAJwGpIzRQSOFaO0pU6s44Xt8aTwc","recaptchaAudioLang":"en","enableNewTagCreationWarning":true,"insertSpaceAfterNameTabCompletion":false,"id":1,"enableSocialMediaInSharePopup":true},"user":{"fkey":"854f77cbe5f2c1ef88213c404c702005","rep":0,"isAnonymous":true,"isAnonymousNetworkWide":true}}); StackExchange.using.setCacheBreakers({"js/prettify-full.en.js":"d27a06f9e057","js/moderator.en.js":"c7f3a2fe6f43","js/full-anon.en.js":"fcc366214c65","js/full.en.js":"22860c74fefe","js/wmd.en.js":"4b1b73828836","js/third-party/jquery.autocomplete.min.js":"e5f01e97f7c3","js/third-party/jquery.autocomplete.min.en.js":"","js/mobile.en.js":"3199d1e28733","js/help.en.js":"c8004cc0095d","js/tageditor.en.js":"bd4fb7a0a976","js/tageditornew.en.js":"93c9f772766c","js/inline-tag-editing.en.js":"4fa1a4a3339e","js/revisions.en.js":"47de10a8358f","js/review.en.js":"52b85f4f645b","js/tagsuggestions.en.js":"d1ff9b84abe5","js/post-validation.en.js":"769557d5981d","js/explore-qlist.en.js":"e71f14781288","js/events.en.js":"e27da81910e7","js/keyboard-shortcuts.en.js":"625602e443f6","js/external-editor.en.js":"d55cf33307e5","js/external-editor.en.js":"d55cf33307e5","js/snippet-javascript.en.js":"857907519d98","js/snippet-javascript-codemirror.en.js":"17f3b3b6b34d"}); StackExchange.using("gps", function() { StackExchange.gps.init(true); }); </script> <script> StackExchange.ready(function () { $(\'#nav-tour\').click(function () { StackExchange.using("gps", function() { StackExchange.gps.track("aboutpage.click", { aboutclick_location: "headermain" }, true); }); }); }); </script> </head> <body class="question-page new-topbar"> <noscript><div id="noscript-padding"></div></noscript> <script>(function () { var old = $.fn.contents; $.fn.contents = function () { try { return old.apply(this, arguments); } catch (e) { return $([]); } } })()</script> <iframe id="adzerk-user-match" width="0" height="0" frameborder="0" scrolling="no" onload="window.AUMIframeDone=true" src="https://ssum-sec.casalemedia.com/usermatch?s=183712&amp;cb=https%3A%2F%2Fengine.adzerk.net%2Fudb%2F22%2Fsync%2Fi.gif%3FpartnerId%3D1%26userId%3D" style="display: none;" marginheight="0" marginwidth="0"></iframe> <div id="notify-container"></div> <div id="overlay-header"></div> <div id="custom-header"></div> For example, /a+/ matches the \'a\' in "candy" <script stuff here />more stuff</script>and all the a\'s in "caaaaaaandy", but nothing in "cndy". Matches the preceding expression 0 or 1 time. Equivalent to {0,1}.<script /> <script>this is stuff</script><script src="\'abc\'http://wwwtest.com">code would go here </font> </script>For example, /e?le?/ matches the \'el\' in "angel" and the \'le\' in "angle" and also the \'l\' in "oslo". For example, /Jack(?=Sprat)/ matches \'Jack\' only if it is followed by \'Sprat\'. /Jack(?=Sprat|Frost)/ matches \'Jack\' only if it is followed by \'Sprat\' or \'Frost\'. JackSprat Jack Sprat However, <script></script>neither \'Sprat\' nor \'Frost\' is part of the match results. Here are a few examples: " This is a random sentence \' with a quote, the quote should match" " There is no quote here thats the problem" Anything here should not match but now it does: \' . Some text " some more text " this is a quote : \' that should match " When there is a quote (\') here, the other one does not work : " \' and that\'s perfect " even if you remove the first one this : " (\') " will make it work because of the greedy ( I think ) but ifyou remove those between parenthesis, the other one is matching as of now, which I do not want to happen. Another example would be this one : The following should not work, but it does "This is being quoted" not this: (\') " and this is also being quoted " <div class="topbar"> <div class="topbar-wrapper"> <div class="js-topbar-dialog-corral"> <div class="topbar-dialog siteSwitcher-dialog dno"> <div class="header"> <h3><a href="//stackoverflow.com">current community</a></h3> </div> <div class="modal-content current-site-container"> <ul class="current-site"> <li> <div class="related-links"> <a href="http://chat.stackoverflow.com" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:6 })" >chat</a> </div> <a href="//stackoverflow.com" class="current-site-link site-link js-gps-track" data-id="1" data-gps-track=" site_switcher.click({ item_type:3 })"> <div class="site-icon favicon favicon-stackoverflow" title="Stack Overflow"></div> Stack Overflow </a> </li> <li class="related-site"> <div class="L-shaped-icon-container"> <span class="L-shaped-icon"></span> </div> <a href="http://meta.stackoverflow.com" class="site-link js-gps-track" data-id="552" data-gps-track=" site.switch({ target_site:552, item_type:3 }), site_switcher.click({ item_type:4 })"> <div class="site-icon favicon favicon-stackoverflowmeta" title="Meta Stack Overflow"></div> Meta Stack Overflow </a> </li> <li class="related-site"> <div class="L-shaped-icon-container"> <span class="L-shaped-icon"></span> </div> <a class="site-link js-gps-track" href="//careers.stackoverflow.com?utm_source=stackoverflow.com&amp;utm_medium=site-ui&amp;utm_campaign=multicollider" data-gps-track="site_switcher.click({ item_type:9 })" > <div class="site-icon favicon favicon-careers" title="Stack Overflow Careers"></div> Stack Overflow Careers </a> </li> </ul> </div> <div class="header" id="your-communities-header"> <h3> your communities </h3> </div> <div class="modal-content" id="your-communities-section"> <div class="call-to-login"> <a href="https://stackoverflow.com/users/signup?ssrc=site_switcher&amp;returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f36183788%2fregex-to-match-single-quotes-being-quoted-by-double-quotes" class="login-link js-gps-track" data-gps-track="site_switcher.click({ item_type:10 })" >Sign up</a> or <a href="https://stackoverflow.com/users/login?ssrc=site_switcher&amp;returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f36183788%2fregex-to-match-single-quotes-being-quoted-by-double-quotes" class="login-link js-gps-track" data-gps-track="site_switcher.click({ item_type:11 })" >log in</a> to customize your list. </div> </div> <div class="header"> <h3><a href="//stackexchange.com/sites">more stack exchange communities</a></h3> <a href="http://blog.stackoverflow.com" class="fr">company blog</a> </div> <div class="modal-content"> <div class="child-content"></div> </div> </div> </div> <div class="network-items"> <a href="//stackexchange.com" class="topbar-icon icon-site-switcher yes-hover js-site-switcher-button js-gps-track" data-gps-track="site_switcher.show" title="A list of all 155 Stack Exchange sites"> <span class="hidden-text">Stack Exchange</span> </a> <a href="#" class="topbar-icon icon-inbox yes-hover js-inbox-button" title="Recent inbox messages"> <span class="hidden-text">Inbox</span> <span class="unread-count" style="display:none"></span> </a> <a href="#" class="topbar-icon icon-achievements yes-hover js-achievements-button " data-unread-class="" title="Recent achievements: reputation, badges, and privileges earned"> <span class="hidden-text">Reputation and Badges</span> <span class="unread-count" style="display:none"> </span> </a> </div> <div class="topbar-links"> <div class="links-container"> <span class="topbar-menu-links"> <a href="https://stackoverflow.com/users/signup?ssrc=head&returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f36183788%2fregex-to-match-single-quotes-being-quoted-by-double-quotes" class="login-link">sign up</a> <a href="https://stackoverflow.com/users/login?ssrc=head&returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f36183788%2fregex-to-match-single-quotes-being-quoted-by-double-quotes" class="login-link">log in</a> <a href="/tour">tour</a> <a href="#" class="icon-help js-help-button" title="Help Center and other resources"> help <span class="triangle"></span> </a> <div class="topbar-dialog help-dialog js-help-dialog dno"> <div class="modal-content"> <ul> <li> <a href="/tour" class="js-gps-track" data-gps-track="help_popup.click({ item_type:1 })"> Tour <span class="item-summary"> Start here for a quick overview of the site </span> </a> </li> <li> <a href="/help" class="js-gps-track" data-gps-track="help_popup.click({ item_type:4 })"> Help Center <span class="item-summary"> Detailed answers to any questions you might have </span> </a> </li> <li> <a href="//meta.stackoverflow.com" class="js-gps-track" data-gps-track="help_popup.click({ item_type:2 })"> Meta <span class="item-summary"> Discuss the workings and policies of this site </span> </a> </li> <li> <a href="http://stackoverflow.com/company/about" class="js-gps-track" data-gps-track="help_popup.click({ item_type:6 })"> About Us <span class="item-summary"> Learn more about Stack Overflow the company </span> </a> </li> <li> <a href="https://business.stackoverflow.com/?ref=topbar_help" class="js-gps-track" data-gps-track="help_popup.click({ item_type:7 })"> Business <span class="item-summary"> Learn more about hiring developers or posting ads with us </span> </a> </li> </ul> </div> </div> </span> </div> <div class="search-container"> <form id="search" action="/search" method="get" autocomplete="off"> <input name="q" type="text" placeholder="Search Q&amp;A" value="" tabindex="1" autocomplete="off" maxlength="240" /> </form> </div> </div> </div> </div> <script> StackExchange.ready(function() { StackExchange.topbar.init(); }); </script> <div class="container"> <div id="header"> <br class="cbt"> <div id="hlogo"> <a href="/" > Stack Overflow </a> </div> <div id="hmenus"> <div class="nav mainnavs"> <ul> <li class="youarehere"><a id="nav-questions" href="/questions">Questions</a></li> <li><a id="nav-jobs" href="/jobs">Jobs</a></li> <li><a id="nav-tags" href="/tags">Tags</a></li> <li><a id="nav-users" href="/users">Users</a></li> <li><a id="nav-badges" href="/help/badges">Badges</a></li> </ul> </div> <div class="nav askquestion"> <ul> <li> <a id="nav-askquestion" href="/questions/ask">Ask Question</a> </li> </ul> </div> </div> </div> <div id="content" class="snippet-hidden"> <div itemscope itemtype="http://schema.org/Question"> <link itemprop="image" href="//cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a"> <div id="herobox"> <div id="hero-content"> <div id="close"><a title="click to minimize">_</a></div> <div id="blurb"> Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. <br/> <br/>Join them; it only takes a minute:<br/> <br/> <a href="/users/signup?ssrc=hero&amp;returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f36183788%2fregex-to-match-single-quotes-being-quoted-by-double-quotes" id="tell-me-more" class="button">Sign up</a> </div> <div id="desc"> <b>Join the Stack Overflow community to:</b> <ol id="hiw"> <li id="q">Ask programming questions </li> <li id="an">Answer and help your peers </li> <li id="b">Get recognized for your expertise </li> </ol> </div> <div style="clear: both"></div> </div> <script> StackExchange.ready(function () { var location = 0; if ($("body").hasClass("questions-page")) { location = 1;; } else if ($("body").hasClass("question-page")) { location = 1;; } else if ($("body").hasClass("faq-page")) { location = 5;; } else if ($("body").hasClass("home-page")) { location = 3;; } $(\'#tell-me-more\').click(function () { StackExchange.using("gps", function () { StackExchange.gps.track("hero.action", { hero_action_type: \'cta\', location: location }, true); }); }); $(\'#herobox #close\').click(function () { StackExchange.using("gps", function () { StackExchange.gps.track("hero.action", { hero_action_type: "minimize", location: location }, true); }); $.cookie("hero", "mini", { path: "/", expires: 365 }); $.ajax({ url: "/hero-mini", success: function (data) { $("#herobox").fadeOut("fast", function () { $("#herobox").replaceWith(data); $("#herobox-mini").fadeIn("fast"); }); } }); return false; }); }); </script> </div> <div id="question-header"> <h1 itemprop="name"><a href="/questions/36183788/regex-to-match-single-quotes-being-quoted-by-double-quotes" class="question-hyperlink">Regex to match single quotes being quoted by double-quotes</a></h1> </div> <div id="mainbar"> <div class="question" data-questionid="36183788" id="question"> <script> var ados = ados || {}; ados.run = ados.run || []; ados.run.push(function () { ados_add_placement(22,8277,"adzerk1151348596",4).setZone(43); }); </script> <div class="everyonelovesstackoverflow" id="adzerk1151348596"> </div> <table> <tr> <td class="votecell"> <div class="vote"> <input type="hidden" name="_id_" value="36183788"> <a class="vote-up-off" title="This question shows research effort; it is useful and clear">up vote</a> <span itemprop="upvoteCount" class="vote-count-post ">3</span> <a class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful">down vote</a> <a class="star-off" href="#">favorite</a> <div class="favoritecount"><b></b></div> </div> </td> <td class="postcell"> <div> <div class="post-text" itemprop="text"> <p>Here is a Regex I have been trying to make work:</p> <pre><code>(?:"[^"]*"[^"]*)*?\\"{1}([^"]*?([\']{1,})[^"]*?)\\" </code></pre> <p>It is probably not the most clean nor the most effective way to achieve what I want to do, but I\'m almost there, I think.</p> <p><strong>My goal is to match any single quote (\') <em>that\'s being quoted</em> between double-quotes (")</strong>, so there needs to be an odd amount of double quotes in front of it. I know that for now it only matches the first group of single quotes, that\'s fine. I will eventually use this regex to replace the first occurence then iterate and use it again to replace the others as long as there are some.</p> <p>Here are a few examples:</p> <ul> <li>" This is a random sentence <strong>\'</strong> with a quote, <strong>the quote should match</strong>"</li> <li>" There is no quote here thats the problem" Anything here <strong>should not match</strong> but now it does: <strong>\'</strong> .</li> <li>" Some text " some more text " this <strong>is a quote : \' that should match</strong>" </li> <li>" When there is a quote (\') here, the other one does not work : " \' and that\'s perfect " even if you remove the first one this : " (\') " will make it work because of the greedy ( I think ) but ifyou remove those between parenthesis, the other one is matching as of now, which I do not want to happen.</li> <li>Another example would be this one : The following should not work, but it does "This is being quoted" not this: (\') " and this is also being quoted "</li> </ul> <p>Note that I really do not consider myself an expert, a few days ago I knew almost nothing except the classic [a-zA-Z0-9]... Any help is welcome, I may have overlooked something basic.</p> <p>I have been working it here: <a href="https://regex101.com/r/aE7iB8/1" rel="nofollow">https://regex101.com/r/aE7iB8/1</a></p> </div> <div class="post-taglist"> <a href="/questions/tagged/java" class="post-tag" title="show questions tagged &#39;java&#39;" rel="tag">java</a> <a href="/questions/tagged/regex" class="post-tag" title="show questions tagged &#39;regex&#39;" rel="tag">regex</a> </div> <table class="fw"> <tr> <td class="vt"> <div class="post-menu"><a href="/q/36183788" title="short permalink to this question" class="short-link" id="link-post-36183788">share</a><span class="lsep">|</span><a href="/posts/36183788/edit" class="suggest-edit-post" title="">improve this question</a></div> </td> <td align="right" class="post-signature"> <div class="user-info "> <div class="user-action-time"> <a href="/posts/36183788/revisions" title="show all edits to this post">edited <span title="2016-03-23 18:39:27Z" class="relativetime">Mar 23 at 18:39</span></a> </div> <div class="user-gravatar32"> </div> <div class="user-details"> <div class="-flair"> </div> </div> </div> </td> <td class="post-signature owner"> <div class="user-info "> <div class="user-action-time"> asked <span title="2016-03-23 16:35:05Z" class="relativetime">Mar 23 at 16:35</span> </div> <div class="user-gravatar32"> <a href="/users/4425156/rapha%c3%abl"><div class="gravatar-wrapper-32"><img src="https://graph.facebook.com/807064487/picture?type=large" alt="" width="32" height="32"></div></a> </div> <div class="user-details"> <a href="/users/4425156/rapha%c3%abl">Rapha&#235;l</a> <div class="-flair"> <span class="reputation-score" title="reputation score " dir="ltr">133</span><span title="7 bronze badges"><span class="badge3"></span><span class="badgecount">7</span></span> </div> </div> </div> </td> </tr> </table> </div> </td> </tr> <tr> <td class="votecell"></td> <td> <div id="comments-36183788" class="comments "> <table> <tbody data-remaining-comments-count="0" data-canpost="false" data-cansee="true" data-comments-unavailable="false" data-addlink-disabled="true"> <tr id="comment-60009490" class="comment "> <td> <table> <tbody> <tr> <td class=" comment-score"> &nbsp;&nbsp; </td> <td> &nbsp; </td> </tr> </tbody> </table> </td> <td class="comment-text"> <div style="display: block;" class="comment-body"> <span class="comment-copy">I think you have an incorrect assumption, and that&#39;s that there needs to be an odd number of double quotes in front of it (depending on what text is allowed). What about the counter-example <code>&#39;&quot;&quot;&quot;\\&#39;&quot;&#39;</code>? Instead of using regex, you should definitely be using a stack.</span> &ndash;&nbsp;<a href="/users/2415524/mbomb007" title="1,447 reputation" class="comment-user">mbomb007</a> <span class="comment-date" dir="ltr"><span title="2016-03-23 19:30:19Z" class="relativetime-clean">Mar 23 at 19:30</span></span> <span class="edited-yes" title="this comment was edited 5 times"></span> </div> </td> </tr> <tr id="comment-60010023" class="comment "> <td> <table> <tbody> <tr> <td class=" comment-score"> &nbsp;&nbsp; </td> <td> &nbsp; </td> </tr> </tbody> </table> </td> <td class="comment-text"> <div style="display: block;" class="comment-body"> <span class="comment-copy">I am not sure I understand what you mean, wouldnt the second &#39; be matched if we check if there are an odd number of &quot; in front of it ?</span> &ndash;&nbsp;<a href="/users/4425156/rapha%c3%abl" title="133 reputation" class="comment-user owner">Rapha&#235;l</a> <span class="comment-date" dir="ltr"><span title="2016-03-23 19:48:00Z" class="relativetime-clean">Mar 23 at 19:48</span></span> </div> </td> </tr> <tr id="comment-60010035" class="comment "> <td> <table> <tbody> <tr> <td class=" comment-score"> &nbsp;&nbsp; </td> <td> &nbsp; </td> </tr> </tbody> </table> </td> <td class="comment-text"> <div style="display: block;" class="comment-body"> <span class="comment-copy">It all depends if you allow nested quotes. Either way, regex is the wrong tool for the job.</span> &ndash;&nbsp;<a href="/users/2415524/mbomb007" title="1,447 reputation" class="comment-user">mbomb007</a> <span class="comment-date" dir="ltr"><span title="2016-03-23 19:48:33Z" class="relativetime-clean">Mar 23 at 19:48</span></span> <span class="edited-yes" title="this comment was edited 2 times"></span> </div> </td> </tr> <tr id="comment-60010107" class="comment "> <td> <table> <tbody> <tr> <td class=" comment-score"> &nbsp;&nbsp; </td> <td> &nbsp; </td> </tr> </tbody> </table> </td> <td class="comment-text"> <div style="display: block;" class="comment-body"> <span class="comment-copy">if I add another double-quote in front of it, it then wouldnt match, which is what I am aiming for: &quot;this is some quoted text&quot; this is not &quot; this is &quot;, maybe I dont understand what you&#39;re meaning</span> &ndash;&nbsp;<a href="/users/4425156/rapha%c3%abl" title="133 reputation" class="comment-user owner">Rapha&#235;l</a> <span class="comment-date" dir="ltr"><span title="2016-03-23 19:50:51Z" class="relativetime-clean">Mar 23 at 19:50</span></span> </div> </td> </tr> <tr id="comment-60010239" class="comment "> <td> <table> <tbody> <tr> <td class=" comment-score"> &nbsp;&nbsp; </td> <td> &nbsp; </td> </tr> </tbody> </table> </td> <td class="comment-text"> <div style="display: block;" class="comment-body"> <span class="comment-copy">Ah,no there wont be nested quotes</span> &ndash;&nbsp;<a href="/users/4425156/rapha%c3%abl" title="133 reputation" class="comment-user owner">Rapha&#235;l</a> <span class="comment-date" dir="ltr"><span title="2016-03-23 19:54:55Z" class="relativetime-clean">Mar 23 at 19:54</span></span> </div> </td> </tr> </tbody> </table> </div> <div id="comments-link-36183788" data-rep=50 data-anon=true> <a class="js-add-link comments-link disabled-link " title="Use comments to ask for more information or suggest improvements. Avoid answering questions in comments." >add a comment</a><span class="js-link-separator dno">&nbsp;|&nbsp;</span> <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick=""></a> </div> </td> </tr> </table> </div> <div id="answers"> <a name="tab-top"></a> <div id="answers-header"> <div class="subheader answers-subheader"> <h2> 2 Answers <span style="display:none;" itemprop="answerCount">2</span> </h2> <div> <div id="tabs"> <a href="/questions/36183788/regex-to-match-single-quotes-being-quoted-by-double-quotes?answertab=active#tab-top" data-nav-xhref="" title="Answers with the latest activity first" data-value="active"> active</a> <a href="/questions/36183788/regex-to-match-single-quotes-being-quoted-by-double-quotes?answertab=oldest#tab-top" data-nav-xhref="" title="Answers in the order they were provided" data-value="oldest"> oldest</a> <a class="youarehere" href="/questions/36183788/regex-to-match-single-quotes-being-quoted-by-double-quotes?answertab=votes#tab-top" data-nav-xhref="" title="Answers with the highest score first" data-value="votes"> votes</a> </div> </div> </div> </div> <a name="36186925"></a> <div id="answer-36186925" class="answer accepted-answer" data-answerid="36186925" itemscope itemtype="http://schema.org/Answer" itemprop="acceptedAnswer"> <table> <tr> <td class="votecell"> <div class="vote"> <input type="hidden" name="_id_" value="36186925"> <a class="vote-up-off" title="This answer is useful">up vote</a> <span itemprop="upvoteCount" class="vote-count-post ">2</span> <a class="vote-down-off" title="This answer is not useful">down vote</a> <span class="vote-accepted-on load-accepted-answer-date" title="loading when this answer was accepted...">accepted</span> </div> </td> <td class="answercell"> <div class="post-text" itemprop="text"> <p>Well, here is a regex that works on all your samples - but it\'s a bit longer and not really perfectly readable. I hope I got all the escapes correctly for the java pattern.</p> <pre><code>(?:(?:^|\\\\G(?&lt;!^)[^\'\\"]*\\")[^\\"]*+(?:"[^\\"\']*"[^\\"]*)*+"|\\\\G(?&lt;!^))[^\'\\"]*+(\') </code></pre> <p>This makes use of the <code>\\G</code>-matcher, that will match at the end of the last pattern and of possesive modifiers to avoid unnecessary backtracking.</p> <p>Let\'s start at the end, <code>[^\'\\"]*+(\')</code> matches any character, thats not single or double quote followed by a single quote, that is captured into a group.</p> <p><code>\\\\G(?&lt;!^)</code> matches at the end of the last match (the <code>(?&lt;!^)</code> is used to ensure we are not at the start of the string, as that is the position of <code>\\G</code> in the first run, before anything is matched. So we will just try, if there is another single quote inside the double quotes we were in the last match.</p> <p><code>(?:^|\\\\G(?&lt;!^)[^\'\\"]*\\")[^\\"]*+(?:"[^\\"\']*"[^\\"]*)*+"</code> is used to jump over all sequences that are either outside double quotes or don\'t contain a single quote. <code>^|\\\\G(?&lt;!^)[^\'\\"]*\\"</code> matches either the start of the string (first match) or matches until the closing double quote of our last match, if there is not other single quote inside. <code>[^\\"]*+</code> then matches anything that\'s not a double quote. <code>(?:"[^\\"\']*"[^\\"]*)*+"</code> then matches any double quotes that don\'t contain single quotes and sequences outside single quotes until we reach the double quote that starts our matching for the single quote.</p> <p>But I guess a demo shows it way better than I can explain, so here you are: <a href="https://regex101.com/r/tW5xH4/1" rel="nofollow">https://regex101.com/r/tW5xH4/1</a></p> </div> <table class="fw"> <tr> <td class="vt"> <div class="post-menu"><a href="/a/36186925" title="short permalink to this answer" class="short-link" id="link-post-36186925">share</a><span class="lsep">|</span><a href="/posts/36186925/edit" class="suggest-edit-post" title="">improve this answer</a></div> </td> <td align="right" class="post-signature"> <div class="user-info "> <div class="user-action-time"> <a href="/posts/36186925/revisions" title="show all edits to this post">edited <span title="2016-03-23 19:26:36Z" class="relativetime">Mar 23 at 19:26</span></a> </div> <div class="user-gravatar32"> </div> <div class="user-details"> <div class="-flair"> </div> </div> </div> </td> <td align="right" class="post-signature"> <div class="user-info "> <div class="user-action-time"> answered <span title="2016-03-23 19:20:30Z" class="relativetime">Mar 23 at 19:20</span> </div> <div class="user-gravatar32"> <a href="/users/3836111/sebastian-proske"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/bc8e3526756540925b0536455b280205?s=32&amp;d=identicon&amp;r=PG&amp;f=1" alt="" width="32" height="32"></div></a> </div> <div class="user-details"> <a href="/users/3836111/sebastian-proske">Sebastian Proske</a> <div class="-flair"> <span class="reputation-score" title="reputation score " dir="ltr">1,352</span><span title="1 gold badge"><span class="badge1"></span><span class="badgecount">1</span></span><span title="6 silver badges"><span class="badge2"></span><span class="badgecount">6</span></span><span title="16 bronze badges"><span class="badge3"></span><span class="badgecount">16</span></span> </div> </div> </div> </td> </tr> </table> </td> </tr> <tr> <td class="votecell"></td> <td> <div id="comments-36186925" class="comments "> <table> <tbody data-remaining-comments-count="0" data-canpost="false" data-cansee="true" data-comments-unavailable="false" data-addlink-disabled="true"> <tr id="comment-60010668" class="comment "> <td> <table> <tbody> <tr> <td class=" comment-score"> &nbsp;&nbsp; </td> <td> &nbsp; </td> </tr> </tbody> </table> </td> <td class="comment-text"> <div style="display: block;" class="comment-body"> <span class="comment-copy">Only seems to work in php</span> &ndash;&nbsp;<a href="/users/4425156/rapha%c3%abl" title="133 reputation" class="comment-user owner">Rapha&#235;l</a> <span class="comment-date" dir="ltr"><span title="2016-03-23 20:06:54Z" class="relativetime-clean">Mar 23 at 20:06</span></span> </div> </td> </tr> </tbody> </table> </div> <div id="comments-link-36186925" data-rep=50 data-anon=true> <a class="js-add-link comments-link disabled-link " title="Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”." >add a comment</a><span class="js-link-separator dno">&nbsp;|&nbsp;</span> <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick=""></a> </div> </td> </tr> </table> </div> <script> var ados = ados || {}; ados.run = ados.run || []; ados.run.push(function () { ados_add_placement(22,8277,"adzerk1282216698",4).setZone(44); }); </script> <div class="everyonelovesstackoverflow" id="adzerk1282216698"> </div> <a name="36186022"></a> <div id="answer-36186022" class="answer" data-answerid="36186022" itemscope itemtype="http://schema.org/Answer"> <table> <tr> <td class="votecell"> <div class="vote"> <input type="hidden" name="_id_" value="36186022"> <a class="vote-up-off" title="This answer is useful">up vote</a> <span itemprop="upvoteCount" class="vote-count-post ">1</span> <a class="vote-down-off" title="This answer is not useful">down vote</a> </div> </td> <td class="answercell"> <div class="post-text" itemprop="text"> <p>If you are planning to iterate anyways, I would consider iterating to grab all the things inside double-quotes first, using this regular expression:</p> <p>"(.*?)"</p> <p>This does a non-greedy (first) match of everything between a pair of quotation marks. </p> <p>(see other ways to grab things between quotation marks here: <a href="http://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks">RegEx: Grabbing values between quotation marks</a>) </p> <p>Once you have all the strings inside pairs of double quotes, it will be trivial to match any single quote inside these strings.</p> </div> <table class="fw"> <tr> <td class="vt"> <div class="post-menu"><a href="/a/36186022" title="short permalink to this answer" class="short-link" id="link-post-36186022">share</a><span class="lsep">|</span><a href="/posts/36186022/edit" class="suggest-edit-post" title="">improve this answer</a></div> </td> <td align="right" class="post-signature"> <div class="user-info "> <div class="user-action-time"> answered <span title="2016-03-23 18:28:12Z" class="relativetime">Mar 23 at 18:28</span> </div> <div class="user-gravatar32"> <a href="/users/4901005/shane-bergsma"><div class="gravatar-wrapper-32"><img src="https://lh4.googleusercontent.com/-1IgA2AlHmtQ/AAAAAAAAAAI/AAAAAAAABRU/E9LgXoUQm-Q/photo.jpg?sz=32" alt="" width="32" height="32"></div></a> </div> <div class="user-details"> <a href="/users/4901005/shane-bergsma">Shane Bergsma</a> <div class="-flair"> <span class="reputation-score" title="reputation score " dir="ltr">25</span><span title="6 bronze badges"><span class="badge3"></span><span class="badgecount">6</span></span> </div> </div> </div> </td> </tr> </table> </td> </tr> <tr> <td class="votecell"></td> <td> <div id="comments-36186022" class="comments "> <table> <tbody data-remaining-comments-count="0" data-canpost="false" data-cansee="true" data-comments-unavailable="false" data-addlink-disabled="true"> <tr id="comment-60007787" class="comment "> <td> <table> <tbody> <tr> <td class=" comment-score"> &nbsp;&nbsp; </td> <td> &nbsp; </td> </tr> </tbody> </table> </td> <td class="comment-text"> <div style="display: block;" class="comment-body"> <span class="comment-copy">I am currently working on doing that in Java, but it&#39;d still be nice to do and/or know how to do it using a regex !</span> &ndash;&nbsp;<a href="/users/4425156/rapha%c3%abl" title="133 reputation" class="comment-user owner">Rapha&#235;l</a> <span class="comment-date" dir="ltr"><span title="2016-03-23 18:43:34Z" class="relativetime-clean">Mar 23 at 18:43</span></span> </div> </td> </tr> <tr id="comment-60011002" class="comment "> <td class="comment-actions"> <table> <tbody> <tr> <td class=" comment-score"> <span title="number of &#39;useful comment&#39; votes received" class="cool">1</span> </td> <td> &nbsp; </td> </tr> </tbody> </table> </td> <td class="comment-text"> <div style="display: block;" class="comment-body"> <span class="comment-copy">Good point to be made here about what a regex is good for, because in a lot of cases it makes more sense to use your program to do the processing. A regex is not (practically) a programming language, it&#39;s one of (hopefully) many tools provided by a programming language.</span> &ndash;&nbsp;<a href="/users/1255289/miken32" title="7,846 reputation" class="comment-user">miken32</a> <span class="comment-date" dir="ltr"><span title="2016-03-23 20:17:02Z" class="relativetime-clean">Mar 23 at 20:17</span></span> </div> </td> </tr> </tbody> </table> </div> <div id="comments-link-36186022" data-rep=50 data-anon=true> <a class="js-add-link comments-link disabled-link " title="Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”." >add a comment</a><span class="js-link-separator dno">&nbsp;|&nbsp;</span> <a class="js-show-link comments-link dno" title="expand to show all comments on this post" href=# onclick=""></a> </div> </td> </tr> </table> </div> <a name=\'new-answer\'></a> <form id="post-form" action="/questions/36183788/answer/submit" method="post" class="post-form"> <input type="hidden" id="post-id" value="36183788" /> <input type="hidden" id="qualityBanWarningShown" name="qualityBanWarningShown" value="false" /> <input type="hidden" name="referrer" value=""/> <h2 class="space">Your Answer</h2> <script> StackExchange.ifUsing("editor", function () { StackExchange.using("externalEditor", function () { StackExchange.using("snippets", function () { StackExchange.snippets.init(); }); }); }, "code-snippets"); </script> <script> StackExchange.ready(function() { initTagRenderer("".split(" "), "".split(" ")); StackExchange.using("externalEditor", function() { // Have to fire editor after snippets, if snippets enabled if (StackExchange.options.snippets.enabled) { StackExchange.using("snippets", function() { createEditor(); }); } else { createEditor(); } }); function createEditor() { prepareEditor({ heartbeatType: \'answer\', convertImagesToLinks: true, reputationToPostImages: 10, bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".discard-answer" ,immediatelyShowMarkdownHelp:true }); } }); </script> <div id="post-editor" class="post-editor js-post-editor"> <div style="position: relative;"> <div class="wmd-container"> <div id="wmd-button-bar" class="wmd-button-bar"></div> <textarea id="wmd-input" class="wmd-input" name="post-text" cols="92" rows="15" tabindex="101" data-min-length=""></textarea> </div> </div> <div class="fl" style="margin-top: 8px; height:24px;">&nbsp;</div> <div id="draft-saved" class="draft-saved community-option fl" style="margin-top: 8px; height:24px; display:none;">draft saved</div> <div id="draft-discarded" class="draft-discarded community-option fl" style="margin-top: 8px; height:24px; display:none;">draft discarded</div> <div id="wmd-preview" class="wmd-preview"></div> <div></div> <div class="edit-block"> <input id="fkey" name="fkey" type="hidden" value="854f77cbe5f2c1ef88213c404c702005"> <input id="author" name="author" type="text"> </div> </div> <div style="position: relative;"> <div class="form-item dno new-post-login"> <div class="new-login-form"> <div class="new-login-left"> <h3>Sign up or <a id="login-link" href="/users/login?ssrc=question_page&returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f36183788%2fregex-to-match-single-quotes-being-quoted-by-double-quotes%23new-answer">log in</a></h3> <script> StackExchange.ready(function () { StackExchange.helpers.onClickDraftSave(\'#login-link\'); }); </script> <div class="preferred-login google-login"> <p><span class="icon"></span><span>Sign up using Google</span></p> </div> <div class="preferred-login facebook-login"> <p><span class="icon"></span><span>Sign up using Facebook</span></p> </div> <div class="preferred-login stackexchange-login"> <p><span class="icon"></span><span>Sign up using Email and Password</span></p> </div> </div> <input type="hidden" name="manual-openid" class="manual-openid" /> <input type="hidden" name="use-facebook" class="use-facebook" value="false" /> <input type="hidden" name="use-google" class="use-google" value="false" /> <input type="button" class="submit-openid" value="Submit" style="display:none" /> <div class="new-login-right"> <h3>Post as a guest</h3> <div class="form-item"> <table> <tr> <td class="vm"> <div> <label for="display-name">Name</label> <input id="display-name" name="display-name" type="text" size="30" maxlength="30" value="" tabindex="105"> </div> <div> <label for="m-address">Email</label> <input id="m-address" name="m-address" type="email" size="30" maxlength="100" value="" tabindex="106" placeholder="required, but never shown" /> </div> </td> </tr> </table> </div> </div> </div> </div> <script> StackExchange.ready( function () { StackExchange.openid.initPostLogin(\'.new-post-login\', \'http%3a%2f%2fstackoverflow.com%2fquestions%2f36183788%2fregex-to-match-single-quotes-being-quoted-by-double-quotes%23new-answer\', \'question_page\'); } ); </script> <noscript> <h3>Post as a guest</h3> <div class="form-item"> <table> <tr> <td class="vm"> <div> <label for="display-name">Name</label> <input id="display-name" name="display-name" type="text" size="30" maxlength="30" value="" tabindex="105"> </div> <div> <label for="m-address">Email</label> <input id="m-address" name="m-address" type="email" size="30" maxlength="100" value="" tabindex="106" placeholder="required, but never shown" /> </div> </td> </tr> </table> </div> </noscript> </div> <div class="form-submit cbt"> <input id="submit-button" type="submit" value="Post Your Answer" tabindex="110"> <a href="#" class="btn-clear discard-answer dno">discard</a> <p class="privacy-policy-agreement"> By posting your answer, you agree to the <a href=\'http://stackexchange.com/legal/privacy-policy\' target=\'_blank\'>privacy policy</a> and <a href=\'http://stackexchange.com/legal/terms-of-service\' target=\'_blank\'>terms of service</a>.</p> <input type="hidden" name="legalLinksShown" value="1" /> </div> </form> <h2 class="bottom-notice" data-loc="1"> Not the answer you&#39;re looking for? Browse other questions tagged <a href="/questions/tagged/java" class="post-tag" title="show questions tagged &#39;java&#39;" rel="tag">java</a> <a href="/questions/tagged/regex" class="post-tag" title="show questions tagged &#39;regex&#39;" rel="tag">regex</a> or <a href="/questions/ask">ask your own question</a>. </h2> </div> </div> <div id="sidebar" class="show-votes"> <div class="module question-stats"> <table id="qinfo"> <tr> <td> <p class="label-key">asked</p> </td> <td style="padding-left: 10px"> <p class="label-key" title="2016-03-23 16:35:05Z"><b>1 month ago</b></p> </td> </tr> <tr> <td> <p class="label-key">viewed</p> </td> <td style="padding-left: 10px"> <p class="label-key"> <b>99 times</b> </p> </td> </tr> <tr> <td> <p class="label-key">active</p> </td> <td style="padding-left: 10px"> <p class="label-key"><b><a href="?lastactivity" class="lastactivity-link" title="2016-03-23 19:26:36Z">1 month ago</a></b></p> </td> </tr> </table> </div> <script> var ados = ados || {}; ados.run = ados.run || []; ados.run.push(function () { ados_add_placement(22,8277,"adzerk1688566301",[5,17,2221]).setZone(45); }); </script> <div class="everyonelovesstackoverflow" id="adzerk1688566301"> </div> <div id="hireme"> <script> ;"use strict";(function(n){function it(n,i,r){var u=t.createElement("script"),e="onreadystatechange",o="onload",f="readyState",s=!1;u.async=!0;u.src=n;typeof i=="function"&&(u[o]=u[e]=function(){s||u[f]&&u[f]!=="loaded"&&u[f]!=="complete"||(s=!0,typeof i=="function"&&i(u),u[o]=u[e]=null,r&&u.parentNode.removeChild(u))});ft.appendChild(u)}function rt(n){var i=t.createElement("link");i.type="text/css";i.rel="stylesheet";i.href=n;et.appendChild(i)}function ct(){var n=i.StackExchange,t="options",r="user";return n&&n[t]&&n[t][r]&&n[t][r].accountId}function lt(n){var t,i;return n=ot(f.hash?f.hash.substr(1):"",n||{}),t=n.ac||n.accountId||ct(),t&&(n.ac=t),n.tags||(i=tt(),i.length>0&&(n.tags=i.join(";"))),n.host=f.host.replace(/\\.internal$/,""),n}function at(n,t,i,u){var c=h(n);if(c===null)return function(){};var e=null,f=null,l=r(),a=function a(){g(c)?(s(e),u(!1,r()-l)):f=o(a,t)};return f=o(a,t),i!==undefined&&(e=o(function(){s(f);u(!0,r()-l)},i)),function(){s(f);s(e)}}function vt(n){var u=f.hash.indexOf("large=1")!==-1,e=y(),o=u||!e||n,s=o?1:2,h=a(["hireme","clc-sb"],v),t=[s+"="+h],r=a(["careers1","clc-tlb"],v),i;return r&&t.push("5="+r),i=a(["careers3","clc-mlb"],v),i&&t.push("6="+i),t.join("&")}function ut(n,t){var e=!!h("#careersadsdoublehigh"),s=k({},u,{zones:u.zones||vt(e)}),f=lt(s),o;n&&(f.azt=1);t&&(f.lw=t);typeof i.innerWidth=="number"&&(f.bw=i.innerWidth);b&&(f.ver=b);o=p()-(e+0);o>0&&(f.az="1");var c=st(f,["zones","ip","ac","eng","prov","tags","theme","at","remote","seed","lw","azt","sysadmin","bw","nocpm","jobview","cpview","ver","host","cp","az"]),a=w+"?"+c;l=r();it(a)}function yt(n){function h(){f.forEach(rt);e.forEach(function(n){return pt(n,t[n],s,o)});typeof i.clc_after_load=="function"&&i.clc_after_load()}var t=n.cr,u=n.h,f=n.st,e=Object.keys(t),o=l?r()-l:0,s="//"+u+"/ct";h()}function pt(n,t,i,r){var s=t.cl,c=t.cn,f=t.an,l=t.tr,o=(s||[]).join(" "),u=h("#"+n);u&&(o&&(u.className+=" "+o),u.innerHTML=c.replace("&pt=0","&pt="+(r||0)),u.onmousedown=function(n){for(var t=n.target,r,o,s;t.tagName!=="A"&&t!==u;)t=t.parentNode;t!==u&&(r=[],f&&r.push("an="+f),o=[].filter.call(t.attributes,function(n){return/^data-/.test(n.name)}),o.length>0&&o.forEach(function(n){var t=n.name.replace(/^data-/,"");r.push(e(t)+"="+e(n.value))}),r.push("tr="+l),s="",r.length>0&&(s="?"+r.join("&")),t.href=i+s)})}function wt(n){var i=t.createElement("a");return i.href=n,i.host}function bt(){var i,n;y()?(n=at("#sidebar "+c,20,i,ut),o(function(){var r=h(c),i;g(r)||(r.parentNode.removeChild(r),typeof n=="function"&&n(),i=t.createElement("img"),i.src="//"+wt(w)+"/to.gif",i.style.display="none",t.body.appendChild(i))},2e3)):ut()}var w=n.u,u=n.o,b=n.c,y,p;u=u||{};var k=Object.assign||function(n){for(var i,r,t=1;t<arguments.length;t++){i=arguments[t];for(r in i)Object.prototype.hasOwnProperty.call(i,r)&&(n[r]=i[r])}return n},i=window,f=i.location,e=i.encodeURIComponent,d=i.decodeURIComponent,t=i.document,ft=t.body,et=t.getElementsByTagName("head")[0],o=i.setTimeout,s=i.clearTimeout,c="[id^=adzerk].everyonelovesstackoverflow",l=0,r=function(){return(new Date).getTime()},ot=function(n,t){return n.split(/\\&/g).reduce(function(n,t){var i=t.split("=");return n[d(i[0])]=d(i[1]),n},t||{})},st=function(n,t){return Object.keys(n).filter(function(n){return t.indexOf(n)!==-1}).map(function(t){return e(t)+"="+e(n[t])}).join("&")},g=function(n){return n.innerHTML.replace(/\\s+$/g,"")},nt=t.querySelectorAll.bind(t),h=t.querySelector.bind(t),ht=t.getElementById.bind(t),a=function(n,t){return n.filter(t)[0]},tt=function(){return[].map.call(nt(".post-taglist .post-tag"),function(n){return n.textContent})},v=function(n){return!!ht(n)};y=function(){return p()>0};p=function(){return nt(c).length};i.clc=k(window.clc||{},{init:yt,load:bt,ls:it,as:rt,tags:tt})}).call(null, {"c":"bbdb06f","u":"//clc.stackoverflow.com/p.js"});"use strict";var allowedHosts=["stackoverflow.com","serverfault.com"];(allowedHosts[0]==="*"||allowedHosts.indexOf(location.hostname)!==-1)&&window.clc.load(); </script> </div> <div style="margin-bottom: 10px;"> <style type="text/css"> #newsletter-ad { width: 270px; height: 250px; overflow: hidden; background: url(\'//cdn.sstatic.net/Sites/stackoverflow/img/newsletter-ad.png?v=4\'); padding: 0 15px 0 15px; } #newsletter-ad-header { margin-top: 60px; } #newsletter-ad ul { margin: 1em 0 1em 1.5em; } #newsletter-ad ul li { margin-bottom: 5px; } #newsletter-signup-container { text-align: center; } #newsletter-preview-container { margin-top: 10px; text-align: center; } #newsletter-email-input { width: 200px; } </style> <script> StackExchange.ready(function () { StackExchange.newsletterAd.init(); }); </script> <div id="newsletter-ad"> <p id="newsletter-ad-header">Get the <b>weekly newsletter!</b> In it, you&#39;ll get:</p> <ul> <li>The week&#39;s top questions and answers</li> <li>Important community announcements</li> <li>Questions that need answers</li> </ul> <div id="newsletter-signup-container"><input id="newsletter-signup" type="button" value="Sign up for the newsletter" /></div> <p id="newsletter-preview-container">see an <a href="//stackexchange.com/newsletters/newsletter?site=stackoverflow.com" id="newsletter-preview">example newsletter</a></p> <div class="dno"> <p class="privacy-policy-agreement"> By subscribing, you agree to the <a href=\'http://stackexchange.com/legal/privacy-policy\' target=\'_blank\'>privacy policy</a> and <a href=\'http://stackexchange.com/legal/terms-of-service\' target=\'_blank\'>terms of service</a>.</p> <input type="hidden" name="legalLinksShown" value="1" /> </div> </div> </div> <div class="module sidebar-linked"> <h4 id="h-linked">Linked</h4> <div class="linked" data-tracker="lq=1"> <div class="spacer"> <a href="/q/171480" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted default">74</div> </a> <a href="/questions/171480/regex-grabbing-values-between-quotation-marks" class="question-hyperlink">RegEx: Grabbing values between quotation marks</a> </div> </div> </div> <div class="module sidebar-related"> <h4 id="h-related">Related</h4> <div class="related js-gps-related-questions" data-tracker="rq=1"> <div class="spacer"> <a href="/q/406230" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted extra-large">2233 </div> </a><a href="/questions/406230/regular-expression-to-match-line-that-doesnt-contain-a-word" class="question-hyperlink">Regular expression to match line that doesn&#39;t contain a word?</a> </div> <div class="spacer"> <a href="/q/6364105" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted default">9 </div> </a><a href="/questions/6364105/regex-for-matching-quotes-and-single-quotes" class="question-hyperlink">Regex for matching quotes and single quotes</a> </div> <div class="spacer"> <a href="/q/12401757" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted default">1 </div> </a><a href="/questions/12401757/regex-for-matching-single-double-an-no-quotes" class="question-hyperlink">Regex for matching single,double an no quotes</a> </div> <div class="spacer"> <a href="/q/12742232" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted default">0 </div> </a><a href="/questions/12742232/regex-to-match-words-between-single-or-double-quotes-in-a-string" class="question-hyperlink">Regex to match words between single or double quotes in a string</a> </div> <div class="spacer"> <a href="/q/17009265" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted default">0 </div> </a><a href="/questions/17009265/replace-single-quote-with-double-quote-with-regex" class="question-hyperlink">Replace single quote with double quote with Regex</a> </div> <div class="spacer"> <a href="/q/20263853" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted default">0 </div> </a><a href="/questions/20263853/regex-match-double-single-quote-inside-string" class="question-hyperlink">Regex: Match double single quote inside string</a> </div> <div class="spacer"> <a href="/q/21146610" title="Vote score (upvotes - downvotes)"> <div class="answer-votes default">1 </div> </a><a href="/questions/21146610/javascript-regex-to-match-anything-between-single-quotes-double-quotes-and-rege" class="question-hyperlink">javascript regex to match anything between single quotes, double quotes and regex slashes</a> </div> <div class="spacer"> <a href="/q/27775787" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted default">0 </div> </a><a href="/questions/27775787/regex-to-match-single-quotes-within-double-quotes-separately" class="question-hyperlink">Regex to match single quotes within double quotes (separately)?</a> </div> <div class="spacer"> <a href="/q/28237930" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted default">-1 </div> </a><a href="/questions/28237930/regex-to-match-word-that-is-not-in-double-or-single-quotes" class="question-hyperlink">Regex to match word that is not in double or single quotes</a> </div> <div class="spacer"> <a href="/q/29018148" title="Vote score (upvotes - downvotes)"> <div class="answer-votes answered-accepted default">1 </div> </a><a href="/questions/29018148/regex-to-replace-double-with-single-quotes-if-at-beginning-and-end-of-matching-s" class="question-hyperlink">Regex to replace double with single quotes if at beginning and end of matching string</a> </div> </div> </div> <div id="hot-network-questions" class="module"> <h4> <a href="//stackexchange.com/questions?tab=hot" class="js-gps-track" data-gps-track="posts_hot_network.click({ item_type:1, location:11 })"> Hot Network Questions </a> </h4> <ul> <li > <div class="favicon favicon-workplace" title="The Workplace Stack Exchange"></div><a href="http://workplace.stackexchange.com/questions/66738/gift-to-my-boss-and-manager-on-last-day" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:423 }); posts_hot_network.click({ item_type:2, location:11 })"> Gift to my boss and manager on last day </a> </li> <li > <div class="favicon favicon-scifi" title="Science Fiction &amp; Fantasy Stack Exchange"></div><a href="http://scifi.stackexchange.com/questions/127528/what-is-the-object-in-the-opening-shot-of-the-force-awakens" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:186 }); posts_hot_network.click({ item_type:2, location:11 })"> What is the object in the opening shot of The Force Awakens? </a> </li> <li > <div class="favicon favicon-stackoverflow" title="Stack Overflow"></div><a href="http://stackoverflow.com/questions/37114407/difference-between-template-parameters-typename-vs-non-typenames" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:1 }); posts_hot_network.click({ item_type:2, location:11 })"> difference between template parameters typename vs non typenames? </a> </li> <li > <div class="favicon favicon-codegolf" title="Programming Puzzles &amp; Code Golf Stack Exchange"></div><a href="http://codegolf.stackexchange.com/questions/79644/how-many-steps-does-it-take-from-n-to-1-by-subtracting-the-greatest-divisor" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:200 }); posts_hot_network.click({ item_type:2, location:11 })"> How many steps does it take from n to 1 by subtracting the greatest divisor? </a> </li> <li > <div class="favicon favicon-music" title="Music: Practice &amp; Theory Stack Exchange"></div><a href="http://music.stackexchange.com/questions/44276/why-do-instruments-have-a-key" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:240 }); posts_hot_network.click({ item_type:2, location:11 })"> Why do instruments have a key? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-scifi" title="Science Fiction &amp; Fantasy Stack Exchange"></div><a href="http://scifi.stackexchange.com/questions/127460/why-is-the-laser-dish-in-the-southern-hemisphere-of-the-death-star-rather-than-t" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:186 }); posts_hot_network.click({ item_type:2, location:11 })"> Why is the laser dish in the southern hemisphere of the Death Star rather than the northern one? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-movies" title="Movies &amp; TV Stack Exchange"></div><a href="http://movies.stackexchange.com/questions/52773/why-did-black-panther-not-kill-zemo" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:367 }); posts_hot_network.click({ item_type:2, location:11 })"> Why did Black Panther not kill Zemo? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-rpg" title="Role-playing Games Stack Exchange"></div><a href="http://rpg.stackexchange.com/questions/79864/do-rage-and-uncanny-dodge-stack" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:122 }); posts_hot_network.click({ item_type:2, location:11 })"> Do Rage and Uncanny Dodge stack? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-security" title="Information Security Stack Exchange"></div><a href="http://security.stackexchange.com/questions/122687/what-are-the-negative-aspects-of-creating-fake-security-footprints" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:162 }); posts_hot_network.click({ item_type:2, location:11 })"> What are the negative aspects of creating fake security footprints? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-programmers" title="Programmers Stack Exchange"></div><a href="http://programmers.stackexchange.com/questions/317966/wouldnt-it-be-beneficial-to-write-tests-during-code-review" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:131 }); posts_hot_network.click({ item_type:2, location:11 })"> Wouldn&#39;t it be beneficial to write tests during code review? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-photo" title="Photography Stack Exchange"></div><a href="http://photo.stackexchange.com/questions/77235/why-buy-prime-super-telephoto-lenses-instead-of-zoom-super-telephoto-lenses" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:61 }); posts_hot_network.click({ item_type:2, location:11 })"> Why buy prime super telephoto lenses instead of zoom super telephoto lenses? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-security" title="Information Security Stack Exchange"></div><a href="http://security.stackexchange.com/questions/122507/tracing-the-location-of-a-mobile-ip-from-an-email" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:162 }); posts_hot_network.click({ item_type:2, location:11 })"> Tracing the location of a mobile IP from an email </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-puzzling" title="Puzzling Stack Exchange"></div><a href="http://puzzling.stackexchange.com/questions/32229/dont-try-this-at-home" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:559 }); posts_hot_network.click({ item_type:2, location:11 })"> Don&#39;t try this at home </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-puzzling" title="Puzzling Stack Exchange"></div><a href="http://puzzling.stackexchange.com/questions/32251/im-a-legendary-story-so-who-am-i" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:559 }); posts_hot_network.click({ item_type:2, location:11 })"> I&#39;m a Legendary Story so who am I? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-math" title="Mathematics Stack Exchange"></div><a href="http://math.stackexchange.com/questions/1777344/how-many-non-differentiable-functions-exist" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:69 }); posts_hot_network.click({ item_type:2, location:11 })"> How many non-differentiable functions exist? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-codegolf" title="Programming Puzzles &amp; Code Golf Stack Exchange"></div><a href="http://codegolf.stackexchange.com/questions/79609/index-of-a-multidimensional-array" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:200 }); posts_hot_network.click({ item_type:2, location:11 })"> Index of a multidimensional array </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-emacs" title="Emacs Stack Exchange"></div><a href="http://emacs.stackexchange.com/questions/22159/how-to-refactor-elisp-programs-using-pattern-matching-on-sexps-with-replacement" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:583 }); posts_hot_network.click({ item_type:2, location:11 })"> How to refactor elisp programs using pattern matching on sexps with replacement? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-math" title="Mathematics Stack Exchange"></div><a href="http://math.stackexchange.com/questions/1776904/what-is-the-smallest-number-of-people-in-a-group-so-that-it-is-guaranteed-that" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:69 }); posts_hot_network.click({ item_type:2, location:11 })"> What is the smallest number of people in a group, so that it is guaranteed that three of them will have their birthday in the same month? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-askubuntu" title="Ask Ubuntu"></div><a href="http://askubuntu.com/questions/769580/get-sudo-emails-for-specific-user" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:89 }); posts_hot_network.click({ item_type:2, location:11 })"> Get `sudo` emails for specific user </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-english" title="English Language &amp; Usage Stack Exchange"></div><a href="http://english.stackexchange.com/questions/323803/jane-makes-over-six-figures-how-much-money-does-she-make" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:97 }); posts_hot_network.click({ item_type:2, location:11 })"> &quot;Jane makes over six figures&quot; - how much money does she make? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-movies" title="Movies &amp; TV Stack Exchange"></div><a href="http://movies.stackexchange.com/questions/52769/who-was-the-man-who-slew-the-kingsguard-knight" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:367 }); posts_hot_network.click({ item_type:2, location:11 })"> Who was the man who slew the Kingsguard Knight? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-travel" title="Travel Stack Exchange"></div><a href="http://travel.stackexchange.com/questions/67963/how-can-i-tell-a-deutsche-bahn-train-has-a-supplementary-charge" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:273 }); posts_hot_network.click({ item_type:2, location:11 })"> How can I tell a Deutsche Bahn train has a supplementary charge? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-space" title="Space Exploration Stack Exchange"></div><a href="http://space.stackexchange.com/questions/15198/would-falcon-9-sink-on-gentle-splashdown" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:508 }); posts_hot_network.click({ item_type:2, location:11 })"> Would Falcon 9 sink on gentle splashdown? </a> </li> <li class="dno js-hidden"> <div class="favicon favicon-tex" title="TeX - LaTeX Stack Exchange"></div><a href="http://tex.stackexchange.com/questions/308697/braces-around-both-sides-of-cases-with-text" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:85 }); posts_hot_network.click({ item_type:2, location:11 })"> Braces around both sides of cases (with text) </a> </li> </ul> <a href="#" class="show-more js-show-more js-gps-track" data-gps-track="posts_hot_network.click({ item_type:3, location:11 })"> more hot questions </a> </div> </div> <div id="feed-link"> <div id="feed-link-text"> <a href="/feeds/question/36183788" title="feed of this question and its answers"> <span class="feed-icon"></span>question feed </a> </div> </div> <script> StackExchange.ready(function(){$.get(\'/posts/36183788/ivc/e809\');}); </script> <noscript> <div><img src="/posts/36183788/ivc/e809" class="dno" alt="" width="0" height="0"></div> </noscript><div style="display:none" id="prettify-lang">lang-java</div></div> </div> </div> <div id="footer" class="categories"> <div class="footerwrap"> <div id="footer-menu"> <div class="top-footer-links"> <a href="http://stackoverflow.com/company/about">about us</a> <a href="/tour">tour</a> <a href="/help">help</a> <a href="http://blog.stackoverflow.com?blb=1">blog</a> <a href="http://chat.stackoverflow.com">chat</a> <a href="http://data.stackexchange.com">data</a> <a href="http://stackexchange.com/legal">legal</a> <a href="http://stackexchange.com/legal/privacy-policy">privacy policy</a> <a href="http://stackoverflow.com/company/work-here">work here</a> <a href="http://stackexchange.com/mediakit">advertising info</a> <a onclick=\'StackExchange.switchMobile("on")\'>mobile</a> <b><a href="/contact">contact us</a></b> <b><a href="http://meta.stackoverflow.com">feedback</a></b> </div> <div id="footer-sites"> <table> <tr> <th colspan=3> Technology </th> <th > Life / Arts </th> <th > Culture / Recreation </th> <th > Science </th> <th > Other </th> </tr> <tr> <td> <ol> <li><a href="//stackoverflow.com" title="professional and enthusiast programmers">Stack Overflow</a></li> <li><a href="//serverfault.com" title="system and network administrators">Server Fault</a></li> <li><a href="//superuser.com" title="computer enthusiasts and power users">Super User</a></li> <li><a href="//webapps.stackexchange.com" title="power users of web applications">Web Applications</a></li> <li><a href="//askubuntu.com" title="Ubuntu users and developers">Ask Ubuntu</a></li> <li><a href="//webmasters.stackexchange.com" title="pro webmasters">Webmasters</a></li> <li><a href="//gamedev.stackexchange.com" title="professional and independent game developers">Game Development</a></li> <li><a href="//tex.stackexchange.com" title="users of TeX, LaTeX, ConTeXt, and related typesetting systems">TeX - LaTeX</a></li> </ol></td><td><ol> <li><a href="//programmers.stackexchange.com" title="professional programmers interested in conceptual questions about software development">Programmers</a></li> <li><a href="//unix.stackexchange.com" title="users of Linux, FreeBSD and other Un*x-like operating systems">Unix &amp; Linux</a></li> <li><a href="//apple.stackexchange.com" title="power users of Apple hardware and software">Ask Different (Apple)</a></li> <li><a href="//wordpress.stackexchange.com" title="WordPress developers and administrators">WordPress Development</a></li> <li><a href="//gis.stackexchange.com" title="cartographers, geographers and GIS professionals">Geographic Information Systems</a></li> <li><a href="//electronics.stackexchange.com" title="electronics and electrical engineering professionals, students, and enthusiasts">Electrical Engineering</a></li> <li><a href="//android.stackexchange.com" title="enthusiasts and power users of the Android operating system">Android Enthusiasts</a></li> <li><a href="//security.stackexchange.com" title="information security professionals">Information Security</a></li> </ol></td><td><ol> <li><a href="//dba.stackexchange.com" title="database professionals who wish to improve their database skills and learn from others in the community">Database Administrators</a></li> <li><a href="//drupal.stackexchange.com" title="Drupal developers and administrators">Drupal Answers</a></li> <li><a href="//sharepoint.stackexchange.com" title="SharePoint enthusiasts">SharePoint</a></li> <li><a href="//ux.stackexchange.com" title="user experience researchers and experts">User Experience</a></li> <li><a href="//mathematica.stackexchange.com" title="users of Mathematica">Mathematica</a></li> <li><a href="//salesforce.stackexchange.com" title="Salesforce administrators, implementation experts, developers and anybody in-between">Salesforce</a></li> <li><a href="//expressionengine.stackexchange.com" title="administrators, end users, developers and designers for ExpressionEngine&#174; CMS">ExpressionEngine&#174; Answers</a></li> <li> <a href="http://stackexchange.com/sites#technology" class="more"> more (13) </a> </li> </ol> </td> <td> <ol> <li><a href="//photo.stackexchange.com" title="professional, enthusiast and amateur photographers">Photography</a></li> <li><a href="//scifi.stackexchange.com" title="science fiction and fantasy enthusiasts">Science Fiction &amp; Fantasy</a></li> <li><a href="//graphicdesign.stackexchange.com" title="Graphic Design professionals, students, and enthusiasts">Graphic Design</a></li> <li><a href="//movies.stackexchange.com" title="movie and tv enthusiasts">Movies &amp; TV</a></li> <li><a href="//cooking.stackexchange.com" title="professional and amateur chefs">Seasoned Advice (cooking)</a></li> <li><a href="//diy.stackexchange.com" title="contractors and serious DIYers">Home Improvement</a></li> <li><a href="//money.stackexchange.com" title="people who want to be financially literate">Personal Finance &amp; Money</a></li> <li><a href="//academia.stackexchange.com" title="academics and those enrolled in higher education">Academia</a></li> <li> <a href="http://stackexchange.com/sites#lifearts" class="more"> more (9) </a> </li> </ol> </td> <td> <ol> <li><a href="//english.stackexchange.com" title="linguists, etymologists, and serious English language enthusiasts">English Language &amp; Usage</a></li> <li><a href="//skeptics.stackexchange.com" title="scientific skepticism">Skeptics</a></li> <li><a href="//judaism.stackexchange.com" title="those who base their lives on Jewish law and tradition and anyone interested in learning more">Mi Yodeya (Judaism)</a></li> <li><a href="//travel.stackexchange.com" title="road warriors and seasoned travelers">Travel</a></li> <li><a href="//christianity.stackexchange.com" title="committed Christians, experts in Christianity and those interested in learning more">Christianity</a></li> <li><a href="//gaming.stackexchange.com" title="passionate videogamers on all platforms">Arqade (gaming)</a></li> <li><a href="//bicycles.stackexchange.com" title="people who build and repair bicycles, people who train cycling, or commute on bicycles">Bicycles</a></li> <li><a href="//rpg.stackexchange.com" title="gamemasters and players of tabletop, paper-and-pencil role-playing games">Role-playing Games</a></li> <li> <a href="http://stackexchange.com/sites#culturerecreation" class="more"> more (21) </a> </li> </ol> </td> <td> <ol> <li><a href="//math.stackexchange.com" title="people studying math at any level and professionals in related fields">Mathematics</a></li> <li><a href="//stats.stackexchange.com" title="people interested in statistics, machine learning, data analysis, data mining, and data visualization">Cross Validated (stats)</a></li> <li><a href="//cstheory.stackexchange.com" title="theoretical computer scientists and researchers in related fields">Theoretical Computer Science</a></li> <li><a href="//physics.stackexchange.com" title="active researchers, academics and students of physics">Physics</a></li> <li><a href="//mathoverflow.net" title="professional mathematicians">MathOverflow</a></li> <li><a href="//chemistry.stackexchange.com" title="scientists, academics, teachers and students">Chemistry</a></li> <li><a href="//biology.stackexchange.com" title="biology researchers, academics, and students">Biology</a></li> <li> <a href="http://stackexchange.com/sites#science" class="more"> more (5) </a> </li> </ol> </td> <td> <ol> <li><a href="//stackapps.com" title="apps, scripts, and development with the Stack Exchange API">Stack Apps</a></li> <li><a href="//meta.stackexchange.com" title="meta-discussion of the Stack Exchange family of Q&amp;A websites">Meta Stack Exchange</a></li> <li><a href="//area51.stackexchange.com" title="proposing new sites in the Stack Exchange network">Area 51</a></li> <li><a href="//careers.stackoverflow.com">Stack Overflow Careers</a></li> </ol> </td> </tr> </table> </div> </div> <div id="copyright"> site design / logo &#169; 2016 Stack Exchange Inc; user contributions licensed under <a href="https://creativecommons.org/licenses/by-sa/3.0/" rel="license">cc by-sa 3.0</a> with <a href="http://blog.stackoverflow.com/2009/06/attribution-required/" rel="license">attribution required</a> </div> <div id="svnrev"> rev 2016.5.9.3554 </div> </div> </div> <noscript> <div id="noscript-warning">Stack Overflow works best with JavaScript enabled<img src="http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" class="dno"></div> </noscript> <script>var p = "http", d = "static"; if (document.location.protocol == "https:") { p += "s"; d = "engine"; } var z = document.createElement("script"); z.type = "text/javascript"; z.async = true; z.src = p + "://" + d + ".adzerk.net/ados.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(z, s);</script> <script> var ados = ados || {}; ados.run = ados.run || []; ados.run.push(function () { setTimeout(function () { $("#adzerk-user-match").remove(); }, window.AUMIframeDone ? 0 : 2000); ados_setKeywords(\'java,regex\');; ados_load(); }); </script> <script> (function (i, s, o, g, r, a, m) { i[\'GoogleAnalyticsObject\'] = r; i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })(window, document, \'script\', \'https://www.google-analytics.com/analytics.js\', \'ga\'); ga(\'create\', \'UA-5620270-1\'); ga(\'set\', \'dimension2\', \'|java|regex|\'); ga(\'send\', \'pageview\'); var _qevents = _qevents || [], _comscore = _comscore || []; (function () { var ssl=\'https:\'==document.location.protocol, s=document.getElementsByTagName(\'script\')[0], qc=document.createElement(\'script\'); qc.async=true; qc.src=(ssl?\'https://secure\':\'http://edge\')+\'.quantserve.com/quant.js\'; s.parentNode.insertBefore(qc, s); var sc=document.createElement(\'script\'); sc.async=true; sc.src=(ssl?\'https://sb\':\'http://b\') + \'.scorecardresearch.com/beacon.js\'; s.parentNode.insertBefore(sc, s); })(); _comscore.push({ c1: "2", c2: "17440561" }); _qevents.push({ qacct: "p-c1rF4kxgLUzNc" }); </script> </body> </html>'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php