Skip to content

web search done right

531 KB
Raw Blame
<!DOCTYPE html>


    <html itemscope itemtype="https://schema.org/QAPage" class="html__responsive " lang="en">

    <head>

        <title>html - RegEx match open tags except XHTML self-contained tags - Stack Overflow</title>
        <link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196">
        <link rel="apple-touch-icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a">
        <link rel="image_src" href="https://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">
        <link rel="canonical" href="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags" />
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0">
        <meta property="og:type" content= "website" />
        <meta property="og:url" content="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags"/>
        <meta property="og:site_name" content="Stack Overflow" />
        <meta property="og:image" itemprop="image primaryImageOfPage" content="https://cdn.sstatic.net/Sites/stackoverflow/Img/[email protected]?v=73d79a89bded" />
        <meta name="twitter:card" content="summary"/>
        <meta name="twitter:domain" content="stackoverflow.com"/>
        <meta name="twitter:title" property="og:title" itemprop="name" content="RegEx match open tags except XHTML self-contained tags" />
        <meta name="twitter:description" property="og:description" itemprop="description" content="I need to match all of these opening tags:&#xA;&#xA;&amp;lt;p&amp;gt;&#xA;&amp;lt;a href=&quot;foo&quot;&amp;gt;&#xD;&#xA;But not these:&#xA;&#xA;&amp;lt;br /&amp;gt;&#xA;&amp;lt;hr class=&quot;foo&quot; /&amp;gt;&#xD;&#xA;I came up with this and wanted to make sure I&#x27;ve got it right. I a..." />
    <script id="webpack-public-path" type="text/uri-list">https://cdn.sstatic.net/</script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script defer src="https://cdn.sstatic.net/Js/third-party/npm/@stackoverflow/stacks/dist/js/stacks.min.js?v=facbc6b2f3b6"></script>
    <script src="https://cdn.sstatic.net/Js/stub.en.js?v=0e3ada576039"></script>


    <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Shared/stacks.css?v=5ad0f45f4799">
    <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/stackoverflow/primary.css?v=262abaa77efd">


    
            <link rel="alternate" type="application/atom+xml" title="Feed for question &#x27;RegEx match open tags except XHTML self-contained tags&#x27;" href="/feeds/question/1732348">
            <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/1732348/regex-match-open-tags-except-xhtml-self-contained-tags" />
            <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/1732348/regex-match-open-tags-except-xhtml-self-contained-tags" />
            <meta name="twitter:app:name:googleplay" content="Stack Exchange Android">
            <meta name="twitter:app:url:googleplay" content="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags">
            <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,showTrendingSortLaunchPopover:false,showTrendingSortPostLaunchPopover:false,totalCommentCount:0,shownCommentCount:0,enableTables:true,questionId:1732348});

                styleCode();

                    StackExchange.realtime.subscribeToQuestion('1', '1732348');
                    StackExchange.using("gps", function () { StackExchange.gps.trackOutboundClicks('#content', '.js-post-body'); });


            });
        </script>

        
        
        
        <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Shared/Channels/channels.css?v=d098999fc478">

        
        


    <script type="application/json" data-role="module-args" data-module-name="Shared/options.mod">{"options":{"locale":"en","serverTime":1668500813,"routeName":"Questions/Show","stackAuthUrl":"https://stackauth.com","networkMetaHostname":"meta.stackexchange.com","site":{"name":"Stack Overflow","description":"Q\u0026A for professional and enthusiast programmers","isNoticesTabEnabled":true,"enableNewTagCreationWarning":true,"insertSpaceAfterNameTabCompletion":false,"id":1,"cookieDomain":".stackoverflow.com","childUrl":"https://meta.stackoverflow.com","negativeVoteScoreFloor":null,"enableSocialMediaInSharePopup":true,"protocol":"https"},"user":{"fkey":"ca9d9b394875f6ac7a25f1ad0c7b366bef60d37f2ac94c5aa28e142974eade95","tid":"a3204cf0-7ac6-2f70-ab9d-307215f2206c","rep":0,"isAnonymous":true,"isAnonymousNetworkWide":true},"events":{"postType":{"question":1},"postEditionSection":{"title":1,"body":2,"tags":3}},"svgIconPath":"https://cdn.sstatic.net/Img/stacks-icons","svgIconHash":"152dfe64472f"}}</script>
<script type="application/json" data-role="module-args" data-module-name="Shared/settings.mod">{"settings":{"userMessaging":{"showNewFeatureNotice":true},"tags":{},"subscriptions":{"defaultBasicMaxTrueUpSeats":250,"defaultFreemiumMaxTrueUpSeats":50,"defaultMaxTrueUpSeats":1000},"snippets":{"renderDomain":"stacksnippets.net","snippetsEnabled":true},"site":{"allowImageUploads":true,"enableImgurHttps":true,"enableUserHovercards":true,"forceHttpsImages":true,"stacksEditorPreviewEnabled":true,"styleCode":true},"questions":{"enableQuestionTitleLengthLiveWarning":true,"enableSavesFeature":true,"maxTitleSize":150,"questionTitleLengthStartLiveWarningChars":50},"intercom":{"appId":"inf0secd","hostBaseUrl":"https://stacksnippets.net"},"paths":{"jQueryUICSSPath":"https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/themes/smoothness/jquery-ui.css","jQueryUIJSPath":"https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"},"monitoring":{"clientTimingsAbsoluteTimeout":30000,"clientTimingsDebounceTimeout":1000},"mentions":{"maxNumUsersInDropdown":50},"markdown":{"enableTables":true},"legal":{"oneTrustConfigId":"c3d9f1e3-55f3-4eba-b268-46cee4c6789c"},"flags":{"allowRetractingCommentFlags":true,"allowRetractingFlags":true},"elections":{"opaVoteResultsBaseUrl":"https://www.opavote.com/results/"},"comments":{},"accounts":{"currentPasswordRequiredForChangingStackIdPassword":true}}}</script>
<script>StackExchange.init();</script>

    <script>
        StackExchange.using.setCacheBreakers({"Js/adops.en.js":"6da43f5e0a84","Js/ask.en.js":"","Js/begin-edit-event.en.js":"dd955babf04d","Js/copy-transpiled.en.js":"e7855bee94f2","Js/events.en.js":"","Js/explore-qlist.en.js":"2b1f34938b8b","Js/full-anon.en.js":"72dd1e0db5d6","Js/full.en.js":"225ffc0e04e4","Js/highlightjs-loader.en.js":"a284064706b3","Js/inline-tag-editing.en.js":"629d801833ec","Js/keyboard-shortcuts.en.js":"a715495ee04f","Js/markdown-it-loader.en.js":"5818ef89ff9d","Js/moderator.en.js":"b08f5d20ce12","Js/postCollections-transpiled.en.js":"529276cfb7ae","Js/post-validation.en.js":"a49eba10a0e2","Js/question-editor.en.js":"","Js/review-v2-transpiled.en.js":"d5efdefd09e8","Js/revisions.en.js":"a86490719687","Js/stacks-editor.en.js":"198834eebc62","Js/tageditor.en.js":"825c9597ce2d","Js/tageditornew.en.js":"4340d4f2a34c","Js/tagsuggestions.en.js":"1bcff7d98f97","Js/unlimited-transpiled.en.js":"7ed67670b600","Js/wmd.en.js":"6a59bb1514a2","Js/snippet-javascript-codemirror.en.js":"73fce5cc7219"});
        StackExchange.using("gps", function() {
             StackExchange.gps.init(false);
        });
    </script>
    <noscript id="noscript-css"><style>body,.s-topbar{margin-top:1.9em}</style></noscript>
    </head>
    <body class="question-page unified-theme">
    <div id="notify-container"></div>
    <div id="custom-header"></div>
        
<header class="s-topbar ps-fixed t0 l0 js-top-bar">
	<div class="s-topbar--container">
			<a href="#" class="s-topbar--menu-btn js-left-sidebar-toggle" role="menuitem" aria-haspopup="true" aria-controls="left-sidebar" aria-expanded="false"><span></span></a>
			<div class="topbar-dialog leftnav-dialog js-leftnav-dialog dno">
				<div class="left-sidebar js-unpinned-left-sidebar" data-can-be="left-sidebar" data-is-here-when="sm"></div>
			</div>
				<a href="https://stackoverflow.com" class="s-topbar--logo js-gps-track"
		   data-gps-track="top_nav.click({is_current:false, location:2, destination:8})">
					<span class="-img _glyph">Stack Overflow</span>
				</a>



			<ol class="s-navigation" role="presentation">

					<li class="md:d-none">
						<a href="https://stackoverflow.co/" class="s-navigation--item js-gps-track"
				   data-gps-track="top_nav.products.click({location:2, destination:7})"
				   data-ga="[&quot;top navigation&quot;,&quot;about menu click&quot;,null,null,null]">About</a>
					</li>

				<li>
					<a href="#"
				   class="s-navigation--item js-gps-track js-products-menu"
				   aria-controls="products-popover"
				   data-controller="s-popover"
				   data-action="s-popover#toggle"
				   data-s-popover-placement="bottom"
				   data-s-popover-toggle-class="is-selected"
				   data-gps-track="top_nav.products.click({location:2, destination:1})"
				   data-ga="[&quot;top navigation&quot;,&quot;products menu click&quot;,null,null,null]">
						Products
					</a>
				</li>

					<li class="md:d-none">
						<a href="/teams" class="s-navigation--item js-gps-track"
				   data-gps-track="top_nav.products.click({location:2, destination:7})"
				   data-ga="[&quot;top navigation&quot;,&quot;learn more - teams&quot;,null,null,null]">For Teams</a>
					</li>
			</ol>
			<div class="s-popover ws2 mtn2 p0"
			 id="products-popover"
			 role="menu"
			 aria-hidden="true">
				<div class="s-popover--arrow"></div>
				<ol class="list-reset s-anchors s-anchors__inherit">
					<li class="m6">
						<a href="/questions" class="bar-sm p6 d-block h:bg-black-100 js-gps-track"
					   data-gps-track="top_nav.products.click({location:2, destination:2})"
					   data-ga="[&quot;top navigation&quot;,&quot;public qa submenu click&quot;,null,null,null]">
							<span class="fs-body1 d-block">Stack Overflow</span>
							<span class="fs-caption d-block fc-light">Public questions &amp; answers</span>
						</a>
					</li>
					<li class="m6">
						<a href="/teams" class="bar-sm p6 d-block h:bg-black-100 js-gps-track"
					   data-gps-track="top_nav.products.click({location:2, destination:3})"
					   data-ga="[&quot;top navigation&quot;,&quot;teams submenu click&quot;,null,null,null]">
							<span class="fs-body1 d-block">Stack Overflow for Teams</span>
							<span class="fs-caption d-block fc-light">Where developers &amp; technologists share private knowledge with coworkers</span>
						</a>
					</li>
					<li class="m6">
						<a href="https://stackoverflow.co/talent" class="bar-sm p6 d-block h:bg-black-100 js-gps-track"
					   data-gps-track="top_nav.products.click({location:2, destination:5})"
					   data-ga="[&quot;top navigation&quot;,&quot;talent submenu click&quot;,null,null,null]">
							<span class="fs-body1 d-block">Talent</span>
							<span class="fs-caption d-block fc-light">
								Build your employer brand
							</span>
						</a>
					</li>
					<li class="m6">
						<a href="https://stackoverflow.co/advertising" class="bar-sm p6 d-block h:bg-black-100 js-gps-track"
					   data-gps-track="top_nav.products.click({location:2, destination:6})"
					   data-ga="[&quot;top navigation&quot;,&quot;advertising submenu click&quot;,null,null,null]">
							<span class="fs-body1 d-block">Advertising</span>
							<span class="fs-caption d-block fc-light">Reach developers &amp; technologists worldwide</span>
						</a>
					</li>
					<li class="bg-black-025 bt bc-black-075 py6 px6 bbr-md">
						<a href="https://stackoverflow.co/" class="fc-light d-block py6 px6 h:fc-black-800 js-gps-track"
					   data-gps-track="top_nav.products.click({location:2, destination:7})"
					   data-ga="[&quot;top navigation&quot;,&quot;about submenu click&quot;,null,null,null]">About the company</a>
					</li>
				</ol>
			</div>


			<form id="search" role="search" action=/search class="s-topbar--searchbar js-searchbar " autocomplete="off">
					<div class="s-topbar--searchbar--input-group">
						<input name="q"
					   type="text"
					   placeholder="Search&#x2026;"
					   value=""
					   autocomplete="off"
					   maxlength="240"
					   class="s-input s-input__search js-search-field "
					   aria-label="Search"
					   aria-controls="top-search" 
					   data-controller="s-popover"
					   data-action="focus->s-popover#show"
					   data-s-popover-placement="bottom-start" />
						<svg aria-hidden="true" class="s-input-icon s-input-icon__search svg-icon iconSearch" width="18" height="18" viewBox="0 0 18 18"><path d="m18 16.5-5.14-5.18h-.35a7 7 0 1 0-1.19 1.19v.35L16.5 18l1.5-1.5ZM12 7A5 5 0 1 1 2 7a5 5 0 0 1 10 0Z"/></svg>
						<div class="s-popover p0 wmx100 wmn4 sm:wmn-initial js-top-search-popover" id="top-search" role="menu">
    <div class="s-popover--arrow"></div>
    <div class="js-spinner p24 d-flex ai-center jc-center d-none">
        <div class="s-spinner s-spinner__sm fc-orange-400">
            <div class="v-visible-sr">Loading&#x2026;</div>
        </div>
    </div>

    <span class="v-visible-sr js-screen-reader-info"></span>
    <div class="js-ac-results overflow-y-auto hmx3 d-none"></div>

    <div class="js-search-hints" aria-describedby="Tips for searching"></div>
</div>
					</div>
			</form>
		
<nav class="h100 ml-auto overflow-x-auto pr12">
    <ol class="s-topbar--content" role="menubar">
    
    
    
        <li class="js-topbar-dialog-corral" role="presentation">
                

    <div class="topbar-dialog siteSwitcher-dialog dno" role="menu">
        <div class="header fw-wrap">
            <h3 class="flex--item">
                <a href="https://stackoverflow.com">current community</a>
            </h3>
            <div class="flex--item fl1">
                <div class="ai-center d-flex jc-end">
                    <button
                        class="js-close-button s-btn s-btn__muted p0 ml8 d-none sm:d-block"
                        type="button"
                        aria-label="Close"
                    >
                        <svg aria-hidden="true" class="svg-icon iconClear" width="18" height="18" viewBox="0 0 18 18"><path d="M15 4.41 13.59 3 9 7.59 4.41 3 3 4.41 7.59 9 3 13.59 4.41 15 9 10.41 13.59 15 15 13.59 10.41 9 15 4.41Z"/></svg>
                    </button>
                </div>
            </div>
        </div>
        <div class="modal-content bg-powder-050 current-site-container">
            <ul class="current-site ">
                    <li class="d-flex">
                            <div class="fl1">
                <a href="https://stackoverflow.com"
       class="current-site-link site-link js-gps-track d-flex gs8 gsx"
       data-id="1"
       data-gps-track="site_switcher.click({ item_type:3 })">
        <div class="favicon favicon-stackoverflow site-icon flex--item" title="Stack Overflow"></div>
        <span class="flex--item fl1">
            Stack Overflow
        </span>
    </a>

    </div>
    <div class="related-links">
            <a href="https://stackoverflow.com/help" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:14 })">help</a>
            <a href="https://chat.stackoverflow.com/?tab=site&amp;host=stackoverflow.com" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:6 })">chat</a>
    </div>

                    </li>
                    <li class="related-site d-flex">
                            <div class="L-shaped-icon-container">
        <span class="L-shaped-icon"></span>
    </div>

                            <a href="https://meta.stackoverflow.com"
       class=" site-link js-gps-track d-flex gs8 gsx"
       data-id="552"
       data-gps-track="site.switch({ target_site:552, item_type:3 }),site_switcher.click({ item_type:4 })">
        <div class="favicon favicon-stackoverflowmeta site-icon flex--item" title="Meta Stack Overflow"></div>
        <span class="flex--item fl1">
            Meta Stack Overflow
        </span>
    </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=https%3a%2f%2fstackoverflow.com%2fquestions%2f1732348%2fregex-match-open-tags-except-xhtml-self-contained-tags" 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=https%3a%2f%2fstackoverflow.com%2fquestions%2f1732348%2fregex-match-open-tags-except-xhtml-self-contained-tags" 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="https://stackexchange.com/sites">more stack exchange communities</a>
            </h3>
            <a href="https://stackoverflow.blog" class="float-right">company blog</a>
        </div>
        <div class="modal-content">
                <div class="child-content"></div>
        </div>        
    </div>

        </li>
    
            <li role="none"><button class="s-topbar--item s-btn s-btn__icon s-btn__muted d-none sm:d-inline-flex js-searchbar-trigger" role="menuitem" aria-label="Search" aria-haspopup="true" aria-controls="search" title="Click to show search"><svg aria-hidden="true" class="svg-icon iconSearch" width="18" height="18" viewBox="0 0 18 18"><path d="m18 16.5-5.14-5.18h-.35a7 7 0 1 0-1.19 1.19v.35L16.5 18l1.5-1.5ZM12 7A5 5 0 1 1 2 7a5 5 0 0 1 10 0Z"/></svg></button></li>
                        <li role="none">
                            <a href="https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f1732348%2fregex-match-open-tags-except-xhtml-self-contained-tags" class="s-topbar--item s-topbar--item__unset s-btn s-btn__filled ws-nowrap js-gps-track" role="menuitem" rel="nofollow"
               data-gps-track="login.click" data-ga="[&quot;top navigation&quot;,&quot;login button click&quot;,null,null,null]">Log in</a>
                        </li>
                        <li role="none"><a href="https://stackoverflow.com/users/signup?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f1732348%2fregex-match-open-tags-except-xhtml-self-contained-tags" class="s-topbar--item s-topbar--item__unset ml4 s-btn s-btn__primary ws-nowrap" role="menuitem" rel="nofollow" data-ga="[&quot;sign up&quot;,&quot;Sign Up Navigation&quot;,&quot;Header&quot;,null,null]">Sign up</a></li>
    </ol>
</nav>


	</div>
</header>

	<script>
		StackExchange.ready(function () { StackExchange.topbar.init(); });
		StackExchange.scrollPadding.setPaddingTop(50, 10); 
	</script>





    <div class="container">
            

<div id="left-sidebar" data-is-here-when="md lg" class="left-sidebar js-pinned-left-sidebar ps-relative">
    <div class="left-sidebar--sticky-container js-sticky-leftnav">
        <nav role="navigation">
            <ol class="nav-links">
                    

<li class="ps-relative"  aria-current="false">


    <a
       href="/"
       class="pl8 js-gps-track nav-links--link"
       
       data-gps-track="top_nav.click({is_current: false, location:2, destination:8})"
       aria-controls="" data-controller="" data-s-popover-placement="right"
       aria-current="false"
       data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never">
            <div class="d-flex ai-center">
                <div class="flex--item truncate">
                    Home
                </div>
            </div>
    </a>
</li>

                <li>
                    <ol class="nav-links">
                            <li class="fs-fine tt-uppercase ml8 mt16 mb4 fc-light">Public</li>

                            

<li class="ps-relative  youarehere"  aria-current="true">


    <a id="nav-questions"
       href="/questions"
       class="pl8 js-gps-track nav-links--link -link__with-icon"
       
       data-gps-track="top_nav.click({is_current: true, location:2, destination:1})"
       aria-controls="" data-controller="" data-s-popover-placement="right"
       aria-current="false"
       data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never">
<svg aria-hidden="true" class="svg-icon iconGlobe" width="18" height="18" viewBox="0 0 18 18"><path d="M9 1C4.64 1 1 4.64 1 9c0 4.36 3.64 8 8 8 4.36 0 8-3.64 8-8 0-4.36-3.64-8-8-8ZM8 15.32a6.46 6.46 0 0 1-4.3-2.74 6.46 6.46 0 0 1-.93-5.01L7 11.68v.8c0 .88.12 1.32 1 1.32v1.52Zm5.72-2c-.2-.66-1-1.32-1.72-1.32h-1v-2c0-.44-.56-1-1-1H6V7h1c.44 0 1-.56 1-1V5h2c.88 0 1.4-.72 1.4-1.6v-.33a6.45 6.45 0 0 1 3.83 4.51 6.45 6.45 0 0 1-1.51 5.73v.01Z"/></svg>            <span class="-link--channel-name">Questions</span>
    </a>
</li>

                                

<li class="ps-relative"  aria-current="false">


    <a id="nav-tags"
       href="/tags"
       class=" js-gps-track nav-links--link"
       
       data-gps-track="top_nav.click({is_current: false, location:2, destination:2})"
       aria-controls="" data-controller="" data-s-popover-placement="right"
       aria-current="false"
       data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never">
            <div class="d-flex ai-center">
                <div class="flex--item truncate">
                    Tags
                </div>
            </div>
    </a>
</li>

                                

<li class="ps-relative"  aria-current="false">


    <a id="nav-users"
       href="/users"
       class=" js-gps-track nav-links--link"
       
       data-gps-track="top_nav.click({is_current: false, location:2, destination:3})"
       aria-controls="" data-controller="" data-s-popover-placement="right"
       aria-current="false"
       data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never">
            <div class="d-flex ai-center">
                <div class="flex--item truncate">
                    Users
                </div>
            </div>
    </a>
</li>

                                    

<li class="ps-relative"  aria-current="false">


    <a id="nav-companies"
       href="https://stackoverflow.com/jobs/companies?so_medium=stackoverflow&amp;so_source=SiteNav"
       class=" js-gps-track nav-links--link"
       
       data-gps-track="top_nav.click({is_current: false, location:2, destination:12})"
       aria-controls="" data-controller="" data-s-popover-placement="right"
       aria-current="false"
       data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never">
            <div class="d-flex ai-center">
                <div class="flex--item truncate">
                    Companies
                </div>
            </div>
    </a>
</li>

                                <li class="d-flex ml8 mt16 jc-space-between">
                                    <div class="flex--item tt-uppercase tt-uppercase fs-fine fc-light">Collectives</div>
                                    <div class="flex--item fs-fine fc-light">
                                        <a href="javascript:void(0)" class="s-link s-link__inherit mr8 js-gps-track js-collectives-navcta-toggle"
                                           role="button"
                                           aria-controls="popover-discover-collectives"
                                           data-controller="s-popover"
                                           data-action="s-popover#toggle"
                                           data-s-popover-placement="top"
                                           data-s-popover-toggle-class="is-selected"
                                           data-gps-track="top_nav.click({is_current:false, location:2, destination:17})">
                                            <svg aria-hidden="true" class="svg-icon iconInfoSm" width="14" height="14" viewBox="0 0 14 14"><path d="M7 1a6 6 0 1 1 0 12A6 6 0 0 1 7 1Zm1 10V6H6v5h2Zm0-6V3H6v2h2Z"/></svg>
                                        </a>
                                    </div>
                                </li>
                                    

<li class="ps-relative"  aria-current="false">


    <a id="nav-collective-discover"
       href="/collectives"
       class="pl8 ai-center js-collectives-navcta-toggle js-gps-track nav-links--link -link__with-icon"
       
       data-gps-track="top_nav.click({is_current: false, location:2, destination:18})"
       aria-controls="" data-controller="" data-s-popover-placement="right"
       aria-current="false"
       data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never">
<svg aria-hidden="true" class="mt-auto fc-orange-400 svg-icon iconStarVerified" width="18" height="18" viewBox="0 0 18 18"><path d="M9.86.89a1.14 1.14 0 0 0-1.72 0l-.5.58c-.3.35-.79.48-1.23.33l-.72-.25a1.14 1.14 0 0 0-1.49.85l-.14.76c-.1.45-.45.8-.9.9l-.76.14c-.67.14-1.08.83-.85 1.49l.25.72c.15.44.02.92-.33 1.23l-.58.5a1.14 1.14 0 0 0 0 1.72l.58.5c.35.3.48.79.33 1.23l-.25.72c-.23.66.18 1.35.85 1.49l.76.14c.45.1.8.45.9.9l.14.76c.14.67.83 1.08 1.49.85l.72-.25c.44-.15.92-.02 1.23.33l.5.58c.46.52 1.26.52 1.72 0l.5-.58c.3-.35.79-.48 1.23-.33l.72.25c.66.23 1.35-.18 1.49-.85l.14-.76c.1-.45.45-.8.9-.9l.76-.14c.67-.14 1.08-.83.85-1.49l-.25-.72c-.15-.44-.02-.92.33-1.23l.58-.5c.52-.46.52-1.26 0-1.72l-.58-.5c-.35-.3-.48-.79-.33-1.23l.25-.72a1.14 1.14 0 0 0-.85-1.49l-.76-.14c-.45-.1-.8-.45-.9-.9l-.14-.76a1.14 1.14 0 0 0-1.49-.85l-.72.25c-.44.15-.92.02-1.23-.33l-.5-.58Zm-.49 2.67L10.6 6.6c.05.15.19.24.34.25l3.26.22c.36.03.5.48.23.71l-2.5 2.1a.4.4 0 0 0-.14.4l.8 3.16a.4.4 0 0 1-.6.44L9.2 12.13a.4.4 0 0 0-.42 0l-2.77 1.74a.4.4 0 0 1-.6-.44l.8-3.16a.4.4 0 0 0-.13-.4l-2.5-2.1a.4.4 0 0 1 .22-.7l3.26-.23a.4.4 0 0 0 .34-.25l1.22-3.03a.4.4 0 0 1 .74 0Z"/></svg>            <span class="-link--channel-name">Explore Collectives</span>
    </a>
</li>

                    </ol>
                </li>
                   


<li>
    <ol class="nav-links">
                

<li class="js-freemium-cta ps-relative">

    <div class="fs-fine tt-uppercase ml8 mt16 mb8 fc-light">Teams</div>

    <div class="bt bl bb bc-black-075 p12 pb6 fc-black-600 blr-sm overflow-hidden">
        <strong class="fc-black-750 mb6">Stack Overflow for Teams</strong>
        – Start collaborating and sharing organizational knowledge.
        
        <img class="wmx100 mx-auto my8 h-auto d-block" width="139" height="114" src="https://cdn.sstatic.net/Img/teams/teams-illo-free-sidebar-promo.svg?v=47faa659a05e" alt="">

        <a href="https://try.stackoverflow.co/why-teams/?utm_source=so-owned&amp;utm_medium=side-bar&amp;utm_campaign=campaign-38&amp;utm_content=cta" 
           class="w100 s-btn s-btn__primary s-btn__xs bg-orange-400 js-gps-track"
           data-gps-track="teams.create.left-sidenav.click({ Action: 6 })"
           data-ga="[&quot;teams left navigation - anonymous&quot;,&quot;left nav free cta&quot;,&quot;stackoverflow.com/teams/create/free&quot;,null,null]">Create a free Team</a>
        <a href="https://stackoverflow.co/teams" 
           class="w100 s-btn s-btn__muted s-btn__xs js-gps-track"
           data-gps-track="teams.create.left-sidenav.click({ Action: 5 })"
           data-ga="[&quot;teams left navigation - anonymous&quot;,&quot;left nav free cta&quot;,&quot;stackoverflow.com/teams&quot;,null,null]">Why Teams?</a>

    </div>
</li>


            <li class="d-flex ai-center jc-space-between ml8 mt24 mb4 js-create-team-cta d-none">
                <div class="flex--item tt-uppercase fs-fine fc-light">Teams</div>
                <div class="flex--item">
                    <a href="javascript:void(0)" class="s-link p12 fc-black-500 h:fc-black-800 js-gps-track"
                   role="button"
                   aria-controls="popover-teams-create-cta"
                   data-controller="s-popover"
                   data-action="s-popover#toggle"
                   data-s-popover-placement="bottom-start"
                   data-s-popover-toggle-class="is-selected"
                   data-gps-track="teams.create.left-sidenav.click({ Action: ShowInfo })"
                   data-ga="[&quot;teams left navigation - anonymous&quot;,&quot;left nav show teams info&quot;,null,null,null]">
                        <svg aria-hidden="true" class="svg-icon iconInfoSm" width="14" height="14" viewBox="0 0 14 14"><path d="M7 1a6 6 0 1 1 0 12A6 6 0 0 1 7 1Zm1 10V6H6v5h2Zm0-6V3H6v2h2Z"/></svg>
                    </a>

                </div>
            </li>
            <li class="ps-relative js-create-team-cta d-none">
                <a href="https://stackoverflowteams.com/teams/create/free?utm_source=so-owned&amp;utm_medium=side-bar&amp;utm_campaign=campaign-38&amp;utm_content=cta"
               class="pl8 js-gps-track nav-links--link"
               title="Stack Overflow for Teams is a private, secure spot for your organization's questions and answers."
               data-gps-track="teams.create.left-sidenav.click({ Action: FreemiumTeamsCreateClick })"
               data-ga="[&quot;teams left navigation - anonymous&quot;,&quot;left nav team click&quot;,&quot;stackoverflow.com/teams/create/free&quot;,null,null]">
                    <div class="d-flex ai-center">
                        <div class="flex--item s-avatar va-middle bg-orange-400">
                            <div class="s-avatar--letter mtn1">
                                <svg aria-hidden="true" class="svg-icon iconBriefcaseSm" width="14" height="14" viewBox="0 0 14 14"><path d="M4 3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1h.5c.83 0 1.5.67 1.5 1.5v5c0 .83-.67 1.5-1.5 1.5h-7A1.5 1.5 0 0 1 2 10.5v-5C2 4.67 2.67 4 3.5 4H4V3Zm5 1V3H5v1h4Z"/></svg>
                            </div>
                            <svg aria-hidden="true" class="native s-avatar--badge svg-icon iconShieldXSm" width="9" height="10" viewBox="0 0 9 10"><path d="M0 1.84 4.5 0 9 1.84v3.17C9 7.53 6.3 10 4.5 10 2.7 10 0 7.53 0 5.01V1.84Z" fill="var(--white)"/><path d="M1 2.5 4.5 1 8 2.5v2.51C8 7.34 5.34 9 4.5 9 3.65 9 1 7.34 1 5.01V2.5Zm2.98 3.02L3.2 7h2.6l-.78-1.48a.4.4 0 0 1 .15-.38c.34-.24.73-.7.73-1.14 0-.71-.5-1.23-1.41-1.23-.92 0-1.39.52-1.39 1.23 0 .44.4.9.73 1.14.12.08.18.23.15.38Z" fill="var(--black-500)"/></svg>
                        </div>
                        <div class="flex--item pl6">
                            Create free Team
                        </div>
                    </div>
                </a>
            </li>
    </ol>
</li>
            </ol>
        </nav>
    </div>

        <div class="s-popover mt4 ws3"
            id="teams-are-moving-popover"
            role="menu">
            <div class="s-popover--arrow"></div>
            <p>Stack Overflow for Teams is moving to its own domain! When the migration is complete, you will access your Teams at <span class="fs-italic">stackoverflowteams.com</span>, and they will no longer appear in the left sidebar on <span class="fs-italic">stackoverflow.com</span>.</p>
            <p>Check your email for updates.</p>
        </div>

        <div class="s-popover ws2" id="popover-discover-collectives" role="menu">
            <div class="s-popover--arrow"></div>
            <div>
                <svg aria-hidden="true" class="fc-orange-500 float-right ml24 svg-spot spotCollective" width="48" height="48" viewBox="0 0 48 48"><path d="M25.5 7a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM14 18.25c0-.69.56-1.25 1.25-1.25h22.5c.69 0 1.25.56 1.25 1.25V37.5a1 1 0 0 1-1.6.8l-4.07-3.05a1.25 1.25 0 0 0-.75-.25H15.25c-.69 0-1.25-.56-1.25-1.25v-15.5ZM7 24.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0ZM25.5 48a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM48 24.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0Z" opacity=".2"/><path d="M21 3.5a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0ZM24.5 2a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3ZM0 23.5a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0ZM3.5 22a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3ZM21 44.5a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0Zm3.5-1.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3Zm20-23a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7ZM43 23.5a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0Zm-23.23-3.14a1 1 0 0 1-.13 1.4l-2.08 1.74 2.08 1.73a1 1 0 1 1-1.28 1.54l-2.42-2.02a1.63 1.63 0 0 1 0-2.5l2.42-2.02a1 1 0 0 1 1.4.13Zm7.59 1.41a1 1 0 1 1 1.28-1.54l2.42 2.02c.78.65.78 1.85 0 2.5l-2.42 2.02a1 1 0 1 1-1.28-1.54l2.08-1.73-2.08-1.73ZM24.12 18a1 1 0 0 1 .87 1.12l-1 8a1 1 0 1 1-1.98-.24l1-8a1 1 0 0 1 1.11-.87Zm-11.87-5C11.01 13 10 14 10 15.25v15.5c0 1.24 1 2.25 2.25 2.25h17.33c.06 0 .11.02.15.05l4.07 3.05a2 2 0 0 0 3.2-1.6V15.25c0-1.24-1-2.25-2.25-2.25h-22.5ZM12 15.25c0-.14.11-.25.25-.25h22.5c.14 0 .25.11.25.25V34.5l-4.07-3.05a2.2 2.2 0 0 0-1.35-.45H12.25a.25.25 0 0 1-.25-.25v-15.5Zm7.24-10.68a1 1 0 1 0-.48-1.94A22.04 22.04 0 0 0 2.91 17.7a1 1 0 1 0 1.92.58 20.04 20.04 0 0 1 14.4-13.72Zm11.05-1.66a1 1 0 0 0-.58 1.92c6.45 1.92 11.54 7 13.46 13.46a1 1 0 1 0 1.92-.58 22.05 22.05 0 0 0-14.8-14.8ZM4.57 28.76a1 1 0 0 0-1.94.48 22.03 22.03 0 0 0 16.13 16.13 1 1 0 1 0 .48-1.94A20.03 20.03 0 0 1 4.57 28.76Zm40.8.48a1 1 0 1 0-1.94-.48 20.04 20.04 0 0 1-13.72 14.41 1 1 0 0 0 .58 1.92 22.04 22.04 0 0 0 15.08-15.85Z"/></svg>
                <h5 class="pt4 fw-bold">Collectives™ on Stack Overflow</h5>
                <p class="my16 fs-caption fc-medium">Find centralized, trusted content and collaborate around the technologies you use most.</p>
                <a href="/collectives"
               class="js-gps-track s-btn s-btn__primary s-btn__xs"
               data-gps-track="top_nav.click({is_current:false, location:2, destination:18})">
                    Learn more about Collectives
                </a>
            </div>
        </div>


        <div class="s-popover ws2"
         id="popover-teams-create-cta"
         role="menu"
         aria-hidden="true">
            <div class="s-popover--arrow"></div>

            <div class="ps-relative overflow-hidden">
                <p class="mb2"><strong>Teams</strong></p>
                <p class="mb12 fs-caption fc-black-400">Q&amp;A for work</p>
                <p class="mb12 fs-caption fc-medium">Connect and share knowledge within a single location that is structured and easy to search.</p>
                <a href="https://stackoverflow.co/teams"
               class="js-gps-track s-btn s-btn__primary s-btn__xs"
               data-gps-track="teams.create.left-sidenav.click({ Action: CtaClick })"
               data-ga="[&quot;teams left navigation - anonymous&quot;,&quot;left nav cta&quot;,&quot;stackoverflow.com/teams&quot;,null,null]">
                    Learn more about Teams
                </a>
            </div>

            <div class="ps-absolute t8 r8">
                <svg aria-hidden="true" class="fc-orange-500 svg-spot spotPeople" width="48" height="48" viewBox="0 0 48 48"><path d="M13.5 28a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9ZM7 30a1 1 0 0 1 1-1h11a1 1 0 0 1 1 1v5h11v-5a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v10a2 2 0 0 1-2 2H33v5a1 1 0 0 1-1 1H20a1 1 0 0 1-1-1v-5H8a1 1 0 0 1-1-1V30Zm25-6.5a4.5 4.5 0 1 0 9 0 4.5 4.5 0 0 0-9 0ZM24.5 34a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9Z" opacity=".2"/><path d="M16.4 26.08A6 6 0 1 0 7.53 26C5.64 26.06 4 27.52 4 29.45V40a1 1 0 0 0 1 1h9a1 1 0 1 0 0-2h-4v-7a1 1 0 1 0-2 0v7H6v-9.55c0-.73.67-1.45 1.64-1.45H16a1 1 0 0 0 .4-1.92ZM12 18a4 4 0 1 1 0 8 4 4 0 0 1 0-8Zm16.47 14a6 6 0 1 0-8.94 0A3.6 3.6 0 0 0 16 35.5V46a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1V35.5c0-1.94-1.64-3.42-3.53-3.5ZM20 28a4 4 0 1 1 8 0 4 4 0 0 1-8 0Zm-.3 6h8.6c1 0 1.7.75 1.7 1.5V45h-2v-7a1 1 0 1 0-2 0v7h-4v-7a1 1 0 1 0-2 0v7h-2v-9.5c0-.75.7-1.5 1.7-1.5ZM42 22c0 1.54-.58 2.94-1.53 4A3.5 3.5 0 0 1 44 29.45V40a1 1 0 0 1-1 1h-9a1 1 0 1 1 0-2h4v-7a1 1 0 1 1 2 0v7h2v-9.55A1.5 1.5 0 0 0 40.48 28H32a1 1 0 0 1-.4-1.92A6 6 0 1 1 42 22Zm-2 0a4 4 0 1 0-8 0 4 4 0 0 0 8 0Z"/><g opacity=".35"><path d="M17 10a1 1 0 011-1h12a1 1 0 110 2H18a1 1 0 01-1-1Zm1-5a1 1 0 100 2h12a1 1 0 100-2H18ZM14 1a1 1 0 00-1 1v12a1 1 0 001 1h5.09l4.2 4.2a1 1 0 001.46-.04l3.7-4.16H34a1 1 0 001-1V2a1 1 0 00-1-1H14Zm1 12V3h18v10h-5a1 1 0 00-.75.34l-3.3 3.7-3.74-3.75a1 1 0 00-.71-.29H15Z"/></g></svg>
            </div>
        </div>


</div>






        <div id="content" class="snippet-hidden">

            

<div itemprop="mainEntity" itemscope itemtype="https://schema.org/Question">
    <link itemprop="image" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a">

    <div class="inner-content clearfix">

        

            <div id="question-header" class="d-flex sm:fd-column">
                        <h1 itemprop="name" class="fs-headline1 ow-break-word mb8 flex--item fl1"><a href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags" class="question-hyperlink">RegEx match open tags except XHTML self-contained tags</a></h1>
                <div class="ml12 aside-cta flex--item print:d-none sm:ml0 sm:mb12 sm:order-first sm:as-end">
                        <a href="/questions/ask" class="ws-nowrap s-btn s-btn__primary">
        Ask Question
    </a>

                </div>
            </div>
            <div class="d-flex fw-wrap pb8 mb16 bb bc-black-075">
                    <div class="flex--item ws-nowrap mr16 mb8" title="2009-11-13 22:38:26Z">
                        <span class="fc-light mr2">Asked</span>
                        <time itemprop="dateCreated" datetime="2009-11-13T22:38:26">13 years ago</time>
                    </div>
                    <div class="flex--item ws-nowrap mr16 mb8">
                        <span class="fc-light mr2">Modified</span>
                        <a href="?lastactivity" class="s-link s-link__inherit" title="2022-11-07 22:45:58Z">7 days ago</a>
                    </div>
                    <div class="flex--item ws-nowrap mb8" title="Viewed 3,501,951 times">
                        <span class="fc-light mr2">Viewed</span>
                        3.5m times
                    </div>
            </div>
            <div id="mainbar" role="main" aria-label="question and answers">

                
<div class="question js-question" data-questionid="1732348" data-position-on-page="0" data-score="2102"  id="question">
    <style>
    </style>
<div class="js-zone-container zone-container-main">
    <div id="dfp-tlb" class="everyonelovesstackoverflow everyoneloves__top-leaderboard everyoneloves__leaderboard"></div>
		<div class="js-report-ad-button-container " style="width: 728px"></div>
</div>

    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1732348">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This question shows research effort; it is useful and clear"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="2102">
            2102
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This question does not show any research effort; it is unclear or not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1732348"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this question."
        aria-pressed="false"
        data-post-id="1732348"
        data-post-type-id="1"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>








    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732348/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="postcell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
                    <div>
            <aside class="s-notice s-notice__info post-notice js-post-notice mb16" role="status">
        <div class="d-flex fd-column fw-nowrap">
            <div class="d-flex fw-nowrap">
                    <div class="flex--item mr8">
                        <svg aria-hidden="true" class="svg-icon iconLock" width="18" height="18" viewBox="0 0 18 18"><path d="M16 9a2 2 0 0 0-2-2V6A5 5 0 0 0 4 6v1a2 2 0 0 0-2 2v6c0 1.1.9 2 2 2h10a2 2 0 0 0 2-2V9Zm-7 5a2 2 0 1 1 0-4 2 2 0 0 1 0 4Zm3.1-7H5.9V6a3.1 3.1 0 0 1 6.2 0v1Z"/></svg>
                    </div>
                <div class="flex--item wmn0 fl1 lh-lg">
                    <div class="flex--item fl1 lh-lg">
                        <b>Locked</b>. Comments on this question have been disabled, but it is still accepting new answers and other interactions. <a href="/help/locked-posts">Learn more</a>.
                        
                    </div>
                </div>
            </div>
        </div>
</aside>

    </div>

<p>I need to match all of these opening tags:</p>

<pre><code>&lt;p&gt;
&lt;a href="foo"&gt;
</code></pre>

<p>But not these:</p>

<pre><code>&lt;br /&gt;
&lt;hr class="foo" /&gt;
</code></pre>

<p>I came up with this and wanted to make sure I've got it right. I am only capturing the <code>a-z</code>.</p>

<pre><code>&lt;([a-z]+) *[^/]*?&gt;
</code></pre>

<p>I believe it says:</p>

<ul>
<li>Find a less-than, then</li>
<li>Find (and capture) a-z one or more times, then</li>
<li>Find zero or more spaces, then</li>
<li>Find any character zero or more times, greedy, except <code>/</code>, then</li>
<li>Find a greater-than</li>
</ul>

<p>Do I have that right? And more importantly, what do you think?</p>
    </div>

        <div class="mt24 mb12">
            <div class="post-taglist d-flex gs4 gsy fd-column">
                <div class="d-flex ps-relative fw-wrap">
                    <ul class='ml0 list-ls-none js-post-tag-list-wrapper d-inline'><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/html" class="post-tag" title="show questions tagged &#39;html&#39;" aria-label="show questions tagged &#39;html&#39;" rel="tag" aria-labelledby="html-container">html</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/regex" class="post-tag" title="show questions tagged &#39;regex&#39;" aria-label="show questions tagged &#39;regex&#39;" rel="tag" aria-labelledby="regex-container">regex</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/xhtml" class="post-tag" title="show questions tagged &#39;xhtml&#39;" aria-label="show questions tagged &#39;xhtml&#39;" rel="tag" aria-labelledby="xhtml-container">xhtml</a></li></ul>
                </div>
            </div>
        </div>

    <div class="mb0 ">
        <div class="mt16 d-flex gs8 gsy fw-wrap jc-end ai-start pt4 mb16">
            <div class="flex--item mr16 fl1 w96">
                


<div class="js-post-menu pt2" data-post-id="1732348">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/q/1732348"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this question"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 1 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this question"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="question"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="1"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1732348" class="s-btn s-btn__link js-follow-post js-follow-question js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 1 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this question to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>

                <div class="post-signature flex--item">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732348/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 1 })">edited <span title='2012-05-26 20:37:05Z' class='relativetime'>May 26, 2012 at 20:37</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
                </div>
            <div class="post-signature flex--item">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732348" href="/posts/1732348/revisions" title="show revision history for this post">
        11 revs, 7 users 58%<br><a href="/users/142233">Jeff</a>

        </a>
    </div>
</div>

            </div>
        </div>
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">0</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1732348" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="1732348" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="false"
                    data-comments-unavailable="true"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1732348" data-rep=50 data-anon=true>
                    <span class="disabled-link">Comments disabled on deleted / locked posts / reviews</span>
                <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="" role="button"></a>
        </div>         
    </div>
    </div>

</div>


<div class="js-zone-container zone-container-responsive">
    <div id="dfp-isb" class="everyonelovesstackoverflow everyoneloves__inline-sidebar mx-auto"></div>
		<div class="js-report-ad-button-container mx-auto" style="width: 300px"></div>
</div>

                <div id="answers">
                    <a name="tab-top"></a>
                    <div id="answers-header">
                        <div class="answers-subheader d-flex ai-center mb8">
                            <div class="flex--item fl1">
                                <h2 class="mb0" data-answercount="35">
                                        35 Answers
                                    <span style="display:none;" itemprop="answerCount">35</span>
                                </h2>
                            </div>
                            <div class="flex--item">
                                

<div class="d-flex g4 gsx ai-center sm:fd-column sm:ai-start">
    <div class="d-flex fd-column ai-end sm:ai-start">
        <label class="flex--item fs-caption" for="answer-sort-dropdown-select-menu">
            Sorted by:
        </label>
        <a 
            class="js-sort-preference-change s-link flex--item fs-fine d-none"
            data-value="ScoreDesc"
            href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?answertab=scoredesc#tab-top"
        >
            Reset to default
        </a>
    </div>
    <div class="flex--item s-select">
        <select id="answer-sort-dropdown-select-menu">
                    <option
                        value=scoredesc
                        selected=selected
                    >
                        Highest score (default)
                    </option>
                    <option
                        value=trending
                    >
                        Trending (recent votes count more)
                    </option>
                    <option
                        value=modifieddesc
                    >
                        Date modified (newest first)
                    </option>
                    <option
                        value=createdasc
                    >
                        Date created (oldest first)
                    </option>
        </select>
    </div>
</div>


                            </div>
                        </div>
                            
                    </div>

<div class="s-pagination site1 themed pager-answers">
<div class="s-pagination--item is-selected" aria-current=&quot;page&quot;>1</div>
<a class="s-pagination--item js-pagination-item" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?page=2&tab=scoredesc#tab-top" rel="" title="Go to page 2">2</a>
<a class="s-pagination--item js-pagination-item" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?page=2&tab=scoredesc#tab-top" rel="next" title="Go to page 2"> Next</a></div>

                                        
<a name="1732454"></a>
<div id="answer-1732454" class="answer js-answer accepted-answer js-accepted-answer" data-answerid="1732454" data-parentid="1732348" data-score="4409" data-position-on-page="1" data-highest-scored="1" data-question-has-accepted-highest-score="1"  itemprop="acceptedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1732454">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="4409">
            4409
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1732454"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1732454"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732454/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
                    <div>
            <aside class="s-notice s-notice__info post-notice js-post-notice mb16" role="status">
        <div class="d-flex fd-column fw-nowrap">
            <div class="d-flex fw-nowrap">
                    <div class="flex--item mr8">
                        <svg aria-hidden="true" class="svg-icon iconLock" width="18" height="18" viewBox="0 0 18 18"><path d="M16 9a2 2 0 0 0-2-2V6A5 5 0 0 0 4 6v1a2 2 0 0 0-2 2v6c0 1.1.9 2 2 2h10a2 2 0 0 0 2-2V9Zm-7 5a2 2 0 1 1 0-4 2 2 0 0 1 0 4Zm3.1-7H5.9V6a3.1 3.1 0 0 1 6.2 0v1Z"/></svg>
                    </div>
                <div class="flex--item wmn0 fl1 lh-lg">
                    <div class="flex--item fl1 lh-lg">
                        <b>Locked</b>. There are <a href="/help/locked-posts">disputes about this answer’s content</a> being resolved at this time. It is not currently accepting new interactions.
                        
                    </div>
                </div>
            </div>
        </div>
</aside>

    </div>

<p>You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. As I have answered in HTML-and-regex questions here so many times before, the use of regex will not allow you to consume HTML. Regular expressions are a tool that is insufficiently sophisticated to understand the constructs employed by HTML. HTML is not a regular language and hence cannot be parsed by regular expressions. Regex queries are not equipped to break down HTML into its meaningful parts. so many times but it is not getting to me. Even enhanced irregular regular expressions as used by Perl are not up to the task of parsing HTML. You will never make me crack. HTML is a language of sufficient complexity that it cannot be parsed by regular expressions. Even Jon Skeet cannot parse HTML using regular expressions. Every time you attempt to parse HTML with regular expressions, the unholy child weeps the blood of virgins, and Russian hackers pwn your webapp. Parsing HTML with regex summons tainted souls into the realm of the living. HTML and regex go together like love, marriage, and ritual infanticide. The &lt;center&gt; cannot hold it is too late. The force of regex and HTML together in the same conceptual space will destroy your mind like so much watery putty. If you parse HTML with regex you are giving in to Them and their blasphemous ways which doom us all to inhuman toil for the One whose Name cannot be expressed in the Basic Multilingual Plane, he comes. HTML-plus-regexp will liquify the n​erves of the sentient whilst you observe, your psyche withering in the onslaught of horror. Rege̿̔̉x-based HTML parsers are the cancer that is killing StackOverflow <i>it is too late it is too late we cannot be saved</i> the transgression of a chi͡ld ensures regex will consume all living tissue (except for HTML which it cannot, as previously prophesied) <i>dear lord help us how can anyone survive this scourge</i> using regex to parse HTML has doomed humanity to an eternity of dread torture and security holes <i>using rege</i>x as a tool to process HTML establishes a brea<i>ch between this world</i> and the dread realm of c͒ͪo͛ͫrrupt entities (like SGML entities, but <i>more corrupt) a mere glimp</i>se of the world of reg​<b>ex parsers for HTML will ins</b>​tantly transport a p<i>rogrammer's consciousness i</i>nto a w<i>orl</i>d of ceaseless screaming, he comes<strike>, the pestilent sl</strike>ithy regex-infection wil​<b>l devour your HT</b>​ML parser, application and existence for all time like Visual Basic only worse <i>he comes he com</i>es <i>do not fi</i>​ght h<b>e com̡e̶s, ̕h̵i</b>​s un̨ho͞ly radiańcé de<i>stro҉ying all enli̍̈́̂̈́ghtenment, HTML tags <b>lea͠ki̧n͘g fr̶ǫm ̡yo​͟ur eye͢s̸ ̛l̕ik͏e liq</b>​uid p</i>ain, the song of re̸gular exp​re<strike>ssion parsing </strike>will exti<i>​nguish the voices of mor​<b>tal man from the sp</b>​here I can see it can you see ̲͚̖͔̙î̩́t̲͎̩̱͔́̋̀ it is beautiful t​</i>he f<code>inal snuf</code>fing o<i>f the lie​<b>s of Man ALL IS LOŚ͖̩͇̗̪̏̈́T A</b></i><b>LL I​S L</b>OST th<i>e pon̷y he come</i>s he c̶̮om<strike>es he co</strike><b><strike>me</strike>s t<i>he</i> ich​</b>or permeat<i>es al</i>l MY FAC<i>E MY FACE ᵒh god n<b>o NO NOO̼</b></i><b>O​O N</b>Θ stop t<i>he an​*̶͑̾̾​̅ͫ͏̙̤g͇̫͛͆̾ͫ̑͆l͖͉̗̩̳̟̍ͫͥͨ</i>e̠̅s<code> ͎a̧͈͖r̽̾̈́͒͑e</code> n<b>​ot rè̑ͧ̌aͨl̘̝̙̃ͤ͂̾̆ ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ T</b>O͇̹̺ͅƝ̴ȳ̳ TH̘<b>Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝</b>S̨̥̫͎̭ͯ̿̔̀ͅ</p>
<hr />
<p>Have you tried using an XML parser instead?</p>
<hr />
<blockquote>
<p><strong>Moderator's Note</strong></p>
<p>This post is locked to prevent inappropriate edits to its content. The post looks exactly as it is supposed to look - there are no problems with its content. Please do not flag it for our attention.</p>
</blockquote>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-13T23:04:30"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1732454">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1732454"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1732454" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732454/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2020-11-12 14:21:18Z' class='relativetime'>Nov 12, 2020 at 14:21</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732454" href="/posts/1732454/revisions" title="show revision history for this post">
        10 revs, 6 users 24%<br><a href="/users/18936">bobince</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">2</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1732454" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="1732454" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="false"
                    data-comments-unavailable="true"
                    data-addlink-disabled="true">

                        <li id="comment-1612336" class="comment js-comment " data-comment-id="1612336" data-comment-owner-id="18936" data-comment-score="179">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">179</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Kobi: I think it&#39;s time for me to quit the post of Assistant Don&#39;t Parse HTML With Regex Officer. No matter how many times we say it, they won&#39;t stop coming every day... every hour even. It is a lost cause, which someone else can fight for a bit. So go on, parse HTML with regex, if you must. It&#39;s only broken code, not life and death.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/18936/bobince"
                            title="520,261 reputation"
                            class="comment-user">bobince</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2009-11-13 23:18:03Z, License: CC BY-SA 2.5' class='relativetime-clean'>Nov 13, 2009 at 23:18</span></span>
            </div>
        </div>
    </li>
    <li id="comment-1647711" class="comment js-comment " data-comment-id="1647711" data-comment-owner-id="68086" data-comment-score="2">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">If you can&#39;t see this post, here&#39;s a screencapture of it in all its glory: <a href="http://imgur.com/gOPS2.png" rel="nofollow noreferrer">imgur.com/gOPS2.png</a></span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/68086/andrew-keeton"
                            title="21,277 reputation"
                            class="comment-user">Andrew Keeton</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2009-11-19 14:37:27Z, License: CC BY-SA 2.5' class='relativetime-clean'>Nov 19, 2009 at 14:37</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1732454" data-rep=50 data-anon=true>
                    <span class="disabled-link">Comments disabled on deleted / locked posts / reviews</span>
                <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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

<div class="js-zone-container zone-container-main">
    <div id="dfp-mlb" class="everyonelovesstackoverflow everyoneloves__mid-leaderboard everyoneloves__leaderboard"></div>
		<div class="js-report-ad-button-container " style="width: 728px"></div>
</div>
                                        
<a name="1733489"></a>
<div id="answer-1733489" class="answer js-answer" data-answerid="1733489" data-parentid="1732348" data-score="3503" data-position-on-page="2" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1733489">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="3503">
            3503
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1733489"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1733489"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>
            
<div class="js-bounty-award-container flex--item pb4">

    <div class="d-flex fd-column gs4 ai-center">

            <div class="js-bounty-award flex--item s-badge s-badge__bounty s-badge__sm as-center"
                 title="This answer has been awarded bounties worth 50 reputation by ThiefMaster" data-controller="s-tooltip" data-s-tooltip-placement="right">
                +50
            </div>

    </div>
</div>


    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1733489/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>While <em>arbitrary</em> HTML with only a regex is impossible, it's sometimes appropriate to use them for parsing a <em>limited, known</em> set of HTML.  </p>

<p>If you have a small set of HTML pages that you want to scrape data from and then stuff into a database, regexes might work fine.  For example, I recently wanted to get the names, parties, and districts of Australian federal Representatives, which I got off of the Parliament's web site.  This was a limited, one-time job.  </p>

<p>Regexes worked just fine for me, and were very fast to set up.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-14T06:27:19"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1733489">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1733489"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1733489" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1733489/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2019-09-19 15:30:40Z' class='relativetime'>Sep 19, 2019 at 15:30</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1733489" href="/posts/1733489/revisions" title="show revision history for this post">
        10 revs, 10 users 36%<br><a href="/users/210931">Kaitlin Duck Sherwood</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">6</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1733489" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="1733489" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="1"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-13095248" class="comment js-comment " data-comment-id="13095248" data-comment-owner-id="173542" data-comment-score="151">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">151</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Also, scraping fairly regularly formatted data from large documents is going to be WAY faster with judicious use of scan &amp; regex than any generic parser. And if you are comfortable with coding regexes, way faster to code than coding xpaths. And almost certainly less fragile to changes in what you are scraping. So bleh.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/173542/michael-johnston"
                            title="5,248 reputation"
                            class="comment-user">Michael Johnston</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-04-17 20:47:27Z, License: CC BY-SA 3.0' class='relativetime-clean'>Apr 17, 2012 at 20:47</span></span>
            </div>
        </div>
    </li>
    <li id="comment-15088991" class="comment js-comment " data-comment-id="15088991" data-comment-owner-id="14122" data-comment-score="300">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">300</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@MichaelJohnston &quot;Less fragile&quot;? Almost certainly not. Regexes care about text-formatting details than an XML parser can silently ignore. Switching between <code>&amp;foo;</code> encodings and <code>CDATA</code> sections? Using an HTML minifier to remove all whitespace in your document that the browser doesn&#39;t render? An XML parser won&#39;t care, and neither will a well-written XPath statement. A regex-based &quot;parser&quot;, on the other hand...</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/14122/charles-duffy"
                            title="267,231 reputation"
                            class="comment-user">Charles Duffy</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-07-11 16:03:24Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 11, 2012 at 16:03</span></span>
            </div>
        </div>
    </li>
    <li id="comment-15115534" class="comment js-comment " data-comment-id="15115534" data-comment-owner-id="1090657" data-comment-score="44">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">44</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@CharlesDuffy for an one time job it&#39;s ok, and for spaces we use \s+</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/1090657/quantum"
                            title="3,540 reputation"
                            class="comment-user">quantum</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-07-12 13:50:01Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 12, 2012 at 13:50</span></span>
            </div>
        </div>
    </li>
    <li id="comment-15120388" class="comment js-comment " data-comment-id="15120388" data-comment-owner-id="14122" data-comment-score="78">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">78</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@xiaomao indeed, if having to know all the gotchas and workarounds to get an 80% solution that fails the rest of the time &quot;works for you&quot;, I can&#39;t stop you. Meanwhile, I&#39;m over on my side of the fence using parsers that work on 100% of syntactically valid XML.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/14122/charles-duffy"
                            title="267,231 reputation"
                            class="comment-user">Charles Duffy</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-07-12 16:07:28Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 12, 2012 at 16:07</span></span>
            </div>
        </div>
    </li>
    <li id="comment-16523188" class="comment js-comment " data-comment-id="16523188" data-comment-owner-id="122087" data-comment-score="419">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">419</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I once had to pull some data off ~10k pages, all with the same HTML template. They were littered with HTML errors that caused parsers to choke, and all their styling was inline or with <code>&lt;font&gt;</code> etc.: no classes or IDs to help navigate the DOM. After fighting all day with the &quot;right&quot; approach, I finally switched to a regex solution and had it working in an hour.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/122087/paul-a-jungwirth"
                            title="22,570 reputation"
                            class="comment-user">Paul A Jungwirth</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-09-07 07:14:38Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 7, 2012 at 7:14</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1733489" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>1</b> more comment</a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1758162"></a>
<div id="answer-1758162" class="answer js-answer" data-answerid="1758162" data-parentid="1732348" data-score="2254" data-position-on-page="3" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1758162">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="2254">
            2254
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1758162"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1758162"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>
            
<div class="js-bounty-award-container flex--item pb4">

    <div class="d-flex fd-column gs4 ai-center">

            <div class="js-bounty-award flex--item s-badge s-badge__bounty s-badge__sm as-center"
                 title="This answer has been awarded bounties worth 100 reputation by Cole Tobin" data-controller="s-tooltip" data-s-tooltip-placement="right">
                +100
            </div>

    </div>
</div>


    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1758162/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>I think the flaw here is that HTML is a <a href="http://en.wikipedia.org/wiki/Context-free_grammar" rel="noreferrer">Chomsky Type 2 grammar (context free grammar)</a> and a regular expression is a <a href="http://en.wikipedia.org/wiki/Regular_grammar" rel="noreferrer">Chomsky Type 3 grammar (regular grammar)</a>. Since a Type 2 grammar is fundamentally more complex than a Type 3 grammar (see the <a href="http://en.wikipedia.org/wiki/Chomsky_hierarchy" rel="noreferrer">Chomsky hierarchy</a>), you can't possibly make this work.</p>
<p>But many will try, and some will even claim success - but until others find the fault and totally mess you up.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-18T18:42:40"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1758162">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1758162"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1758162" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1758162/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2022-08-22 12:51:20Z' class='relativetime'>Aug 22 at 12:51</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1758162" href="/posts/1758162/revisions" title="show revision history for this post">
        10 revs, 9 users 19%<br><a href="/users/22088">Vlad Gudim</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">11</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1758162" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="1758162" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="6"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-12073546" class="comment js-comment " data-comment-id="12073546" data-comment-owner-id="423105" data-comment-score="262">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">262</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">The OP is asking to parse a very limited subset of XHTML: start tags. What makes (X)HTML a CFG is its potential to have elements between the start and end tags of other elements (as in a grammar rule <code>A -&gt; s A e</code>). (X)HTML does <i>not</i> have this property <i>within</i> a start tag: a start tag cannot contain other start tags. The subset that the OP is trying to parse is not a CFG.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/423105/larsh"
                            title="26,946 reputation"
                            class="comment-user">LarsH</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-03-02 08:43:55Z, License: CC BY-SA 3.0' class='relativetime-clean'>Mar 2, 2012 at 8:43</span></span>
            </div>
        </div>
    </li>
    <li id="comment-12448141" class="comment js-comment " data-comment-id="12448141" data-comment-owner-id="960195" data-comment-score="119">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">119</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">In CS theory, regular languages <i>are</i> a strict subset of context-free languages, but regular expression implementations in mainstream programming languages are more powerful.  As <a href="http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/" rel="nofollow noreferrer">noulakaz.net/weblog/2007/03/18/&hellip;</a> describes, so-called &quot;regular expressions&quot; can check for prime numbers in unary, which is certainly something that a regular expression from CS theory can&#39;t accomplish.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/960195/adam-mihalcin"
                            title="13,912 reputation"
                            class="comment-user">Adam Mihalcin</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-03-19 23:50:52Z, License: CC BY-SA 3.0' class='relativetime-clean'>Mar 19, 2012 at 23:50</span></span>
            </div>
        </div>
    </li>
    <li id="comment-13885068" class="comment js-comment " data-comment-id="13885068" data-comment-owner-id="423105" data-comment-score="18">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">18</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@eyelidlessness: the same &quot;only if&quot; applies to all CFGs, does it not? I.e. if the (X)HTML input is not well-formed, not even a full-blown XML parser will work reliably. Maybe if you give examples of the &quot;(X)HTML syntax errors implemented in real world user agents&quot; you&#39;re referring to, I&#39;ll understand what you&#39;re getting at better.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/423105/larsh"
                            title="26,946 reputation"
                            class="comment-user">LarsH</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-05-22 05:09:22Z, License: CC BY-SA 3.0' class='relativetime-clean'>May 22, 2012 at 5:09</span></span>
            </div>
        </div>
    </li>
    <li id="comment-14106691" class="comment js-comment " data-comment-id="14106691" data-comment-owner-id="272427" data-comment-score="93">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">93</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@AdamMihalcin is exactly right. Most extant regex engines are more powerful than Chomsky Type 3 grammars (eg non-greedy matching, backrefs). Some regex engines (such as Perl&#39;s) are Turing complete. It&#39;s true that even those are poor tools for parsing HTML, but this oft-cited argument is not the reason why.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/272427/dubiousjim"
                            title="4,662 reputation"
                            class="comment-user">dubiousjim</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-05-31 13:44:04Z, License: CC BY-SA 3.0' class='relativetime-clean'>May 31, 2012 at 13:44</span></span>
            </div>
        </div>
    </li>
    <li id="comment-55574815" class="comment js-comment " data-comment-id="55574815" data-comment-owner-id="84206" data-comment-score="6">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">6</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">To say the grammar of language A dictates it&#39;s parsing capabilities of another language B based on its grammar, is not valid.  For example, just because HTML is Chomsky Type 2 language, doesn&#39;t mean you could write pure HTML which could parse any Chomsky Type 3 language.  HTML  itself is not a language with any features that give it the ability to parse other languages.  Please don&#39;t say &quot;Javascript&quot;, because javascript is not parsed by something written in HTML.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/84206/aaronls"
                            title="36,504 reputation"
                            class="comment-user">AaronLS</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2015-11-24 23:54:55Z, License: CC BY-SA 3.0' class='relativetime-clean'>Nov 24, 2015 at 23:54</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1758162" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>6</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

<div class="js-zone-container zone-container-main">
    <div id="dfp-smlb" class="everyonelovesstackoverflow everyoneloves__mid-second-leaderboard everyoneloves__leaderboard"></div>
		<div class="js-report-ad-button-container " style="width: 728px"></div>
</div>
                                        
<a name="5236278"></a>
<div id="answer-5236278" class="answer js-answer" data-answerid="5236278" data-parentid="1732348" data-score="1501" data-position-on-page="4" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="5236278">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="1501">
            1501
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-5236278"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="5236278"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/5236278/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>Don't listen to these guys. You totally <strong>can</strong> parse context-free grammars with regex if you break the task into smaller pieces. You can generate the correct pattern with a script that does each of these in order:</p>
<ol>
<li>Solve the Halting Problem.</li>
<li>Square a circle.</li>
<li>Work out the <a href="https://en.wikipedia.org/wiki/Travelling_salesman_problem" rel="nofollow noreferrer">Traveling Salesman Problem</a> in O(log n) or less. If it's any more than that, you'll run out of RAM and the engine will hang.</li>
<li>The pattern will be pretty big, so make sure you have an algorithm that losslessly compresses random data.</li>
<li>Almost there - just divide the whole thing by zero. Easy-peasy.</li>
</ol>
<p>I haven't quite finished the last part myself, but I know I'm getting close. It keeps throwing <code>CthulhuRlyehWgahnaglFhtagnException</code>s for some reason, so I'm going to port it to VB 6 and use <code>On Error Resume Next</code>. I'll update with the code once I investigate this strange door that just opened in the wall. Hmm.</p>
<p>P.S. Pierre de Fermat also figured out how to do it, but the margin he was writing in wasn't big enough for the code.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2011-03-08T17:49:29"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="5236278">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/5236278"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-5236278" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/5236278/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2022-11-07 22:45:58Z' class='relativetime'>Nov 7 at 22:45</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Mar 8, 2011 at 17:49. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-5236278" href="/posts/5236278/revisions" title="show revision history for this post">
        11 revs, 2 users 97%<br><a href="/users/399649">Justin Morgan</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">18</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-5236278" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="5236278" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="13"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-14424307" class="comment js-comment " data-comment-id="14424307" data-comment-owner-id="3408" data-comment-score="96">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">96</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Divison by zero is a much easier problem than the others you mention. If you use intervals, rather than plain floating point arithmetic (which everyone should be but nobody is), you can happily divide something by [an interval containing] zero. The result is simply an interval containing plus and minus infinity.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/3408/rjmunro"
                            title="26,525 reputation"
                            class="comment-user">rjmunro</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-06-14 10:53:39Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jun 14, 2012 at 10:53</span></span>
            </div>
        </div>
    </li>
    <li id="comment-21359004" class="comment js-comment " data-comment-id="21359004" data-comment-owner-id="820321" data-comment-score="180">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">180</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Fermat&#39;s small margin problem has been solved by soft margins in modern text-editing software.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/820321/kd4ttc"
                            title="1,088 reputation"
                            class="comment-user">kd4ttc</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2013-03-01 20:24:32Z, License: CC BY-SA 3.0' class='relativetime-clean'>Mar 1, 2013 at 20:24</span></span>
            </div>
        </div>
    </li>
    <li id="comment-41473537" class="comment js-comment " data-comment-id="41473537" data-comment-owner-id="401828" data-comment-score="65">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">65</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Fermat&#39;s small margin problem has been solved by Randall Munroe by setting the fontsize to zero: <a href="http://xkcd.com/1381/" rel="nofollow noreferrer">xkcd.com/1381</a></span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/401828/heltonbiker"
                            title="25,659 reputation"
                            class="comment-user">heltonbiker</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2014-10-16 19:55:17Z, License: CC BY-SA 3.0' class='relativetime-clean'>Oct 16, 2014 at 19:55</span></span>
            </div>
        </div>
    </li>
    <li id="comment-44568333" class="comment js-comment " data-comment-id="44568333" data-comment-owner-id="202504" data-comment-score="40">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">40</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">FYI: Fermat&#39;s problem <a href="https://en.wikipedia.org/wiki/Wiles%27_proof_of_Fermat%27s_Last_Theorem" rel="nofollow noreferrer">has <i>actually</i> been solved in 1995</a>, and it only took mathematicians 358 years to do so.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/202504/jmiserez"
                            title="2,872 reputation"
                            class="comment-user">jmiserez</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2015-01-22 18:40:17Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jan 22, 2015 at 18:40</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-59460768" class="comment js-comment " data-comment-id="59460768" data-comment-owner-id="880904" data-comment-score="13">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">13</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I was able to bypass that sticky divide-by-zero step by instead using Brownian ratchets yielded from cold fusion...though it only works when I remove the cosmological constant.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/880904/tim-lehner"
                            title="14,492 reputation"
                            class="comment-user">Tim Lehner</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-03-09 18:52:43Z, License: CC BY-SA 3.0' class='relativetime-clean'>Mar 9, 2016 at 18:52</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-5236278" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>13</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1736801"></a>
<div id="answer-1736801" class="answer js-answer" data-answerid="1736801" data-parentid="1732348" data-score="1146" data-position-on-page="5" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1736801">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="1146">
            1146
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1736801"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1736801"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1736801/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p><strong>Disclaimer</strong>: use a parser if you have the option. That said...</p>

<p>This is the regex I use (!) to match HTML tags:</p>

<pre><code>&lt;(?:"[^"]*"['"]*|'[^']*'['"]*|[^'"&gt;])+&gt;
</code></pre>

<p>It may not be perfect, but I ran this code through a <em>lot</em> of HTML. Note that it even catches strange things like <code>&lt;a name="badgenerator""&gt;</code>, which show up on the web.</p>

<p>I guess to make it not match self contained tags, you'd either want to use <a href="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732395#1732395">Kobi</a>'s negative look-behind:</p>

<pre><code>&lt;(?:"[^"]*"['"]*|'[^']*'['"]*|[^'"&gt;])+(?&lt;!/\s*)&gt;
</code></pre>

<p>or just combine if and if not.</p>

<p><strong>To downvoters:</strong> This is working code from an actual product. I doubt anyone reading this page will get the impression that it is socially acceptable to use regexes on HTML. </p>

<p><strong>Caveat</strong>: I should note that this regex still breaks down in the presence of CDATA blocks, comments, and script and style elements. Good news is, you can get rid of those using a regex...  </p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-15T06:37:18"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1736801">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1736801"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1736801" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1736801/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2017-05-23 12:34:53Z' class='relativetime'>May 23, 2017 at 12:34</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1736801" href="/posts/1736801/revisions" title="show revision history for this post">
        5 revs, 2 users 92%<br><a href="/users/7581">itsadok</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">9</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1736801" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="1736801" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="4"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-13616563" class="comment js-comment " data-comment-id="13616563" data-comment-owner-id="1176394" data-comment-score="116">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">116</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I would go with something that works on sane things than weep about not being universally perfect :-)</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/1176394/prajeesh-kumar"
                            title="1,896 reputation"
                            class="comment-user">prajeesh kumar</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-05-10 03:44:49Z, License: CC BY-SA 3.0' class='relativetime-clean'>May 10, 2012 at 3:44</span></span>
            </div>
        </div>
    </li>
    <li id="comment-22995936" class="comment js-comment " data-comment-id="22995936" data-comment-owner-id="639353" data-comment-score="22">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">22</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">so you do not actually solve the parsing problem with regexp only but as a part of the parser this may work. PS: working product doesn&#39;t mean good code. No offence, but this is how industrial programming works and gets their money</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/639353/mishmashru"
                            title="449 reputation"
                            class="comment-user">mishmashru</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2013-04-19 12:18:30Z, License: CC BY-SA 3.0' class='relativetime-clean'>Apr 19, 2013 at 12:18</span></span>
            </div>
        </div>
    </li>
    <li id="comment-35875284" class="comment js-comment " data-comment-id="35875284" data-comment-owner-id="-1" data-comment-score="40">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">40</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Your regex starts fail on the very shortest possible, valid HTML: <code>&lt;!doctype html&gt;&lt;title&gt;&lt;&lt;&#47;title&gt;</code>. Simple <code>&#39;&lt;!doctype html&gt;&lt;title&gt;&lt;&lt;&#47;title&gt;&#39;.match(&#47;&lt;(?:&quot;[^&quot;]*&quot;[&#39;&quot;]*|&#39;[^&#39;]*&#39;[&#39;&quot;]*|[^&#39;&quot;&gt;])+&gt;&#47;g)</code> returns <code>[&quot;&lt;!doctype html&gt;&quot;, &quot;&lt;title&gt;&quot;, &quot;&lt;&lt;&#47;title&gt;&quot;]</code> while should <code>[&quot;&lt;title&gt;&quot;, &quot;&lt;&#47;title&gt;&quot;]</code>.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<span class="comment-user">user1180790</span>
                </div>
                <span class="comment-date" dir="ltr"><span title='2014-05-01 16:48:11Z, License: CC BY-SA 3.0' class='relativetime-clean'>May 1, 2014 at 16:48</span></span>
            </div>
        </div>
    </li>
    <li id="comment-36631031" class="comment js-comment " data-comment-id="36631031" data-comment-owner-id="358236" data-comment-score="3">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">if we&#39;re just trying to match &amp; not match the examples given, /&lt;.([^r&gt;][^&gt;]*)?&gt;/g works :-) // javascript:  &#39;&lt;p&gt; &lt;a href=&quot;foo&quot;&gt; &lt;br /&gt; &lt;hr class=&quot;foo&quot; /&gt;&#39;.match(/&lt;.([^r&gt;][^&gt;]*)?&gt;/g)</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/358236/imma"
                            title="4,892 reputation"
                            class="comment-user">imma</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2014-05-22 16:14:26Z, License: CC BY-SA 3.0' class='relativetime-clean'>May 22, 2014 at 16:14</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-54059485" class="comment js-comment " data-comment-id="54059485" data-comment-owner-id="282601" data-comment-score="2">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">&quot;Is someone using CDATA inside HTML?&quot; - yes, I do. It takes less bytes if you show HTML source code in <code>&lt;pre&gt;</code> tags.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/282601/cweiske"
                            title="29,211 reputation"
                            class="comment-user">cweiske</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2015-10-14 10:56:16Z, License: CC BY-SA 3.0' class='relativetime-clean'>Oct 14, 2015 at 10:56</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1736801" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>4</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="5233151"></a>
<div id="answer-5233151" class="answer js-answer" data-answerid="5233151" data-parentid="1732348" data-score="567" data-position-on-page="6" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="5233151">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="567">
            567
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-5233151"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="5233151"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/5233151/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>There are people that will tell you that the Earth is round (or perhaps that the Earth is an oblate spheroid if they want to use strange words). They are lying.</p>
<p>There are people that will tell you that Regular Expressions shouldn't be recursive. They are limiting you. They need to subjugate you, and they do it by keeping you in ignorance.</p>
<p>You can live in their reality or take the red pill.</p>
<p>Like Lord Marshal (is he a relative of the Marshal .NET class?), I have seen the <strike>Underverse</strike> Stack Based Regex-Verse and returned with <strike>powers</strike> knowledge you can't imagine. Yes, I think there were an Old One or two protecting them, but they were watching football on the TV, so it wasn't difficult.</p>
<p>I think the XML case is quite simple. The RegEx (in the .NET syntax), deflated and coded in base64 to make it easier to comprehend by your feeble mind, should be something like this:</p>
<pre><code>7L0HYBxJliUmL23Ke39K9UrX4HShCIBgEyTYkEAQ7MGIzeaS7B1pRyMpqyqBymVWZV1mFkDM7Z28
995777333nvvvfe6O51OJ/ff/z9cZmQBbPbOStrJniGAqsgfP358Hz8itn6Po9/3eIue3+Px7/3F
86enJ8+/fHn64ujx7/t7vFuUd/Dx65fHJ6dHW9/7fd/t7fy+73Ye0v+f0v+Pv//JnTvureM3b169
OP7i9Ogyr5uiWt746u+BBqc/8dXx86PP7tzU9mfQ9tWrL18d3UGnW/z7nZ9htH/y9NXrsy9fvPjq
i5/46ss3p4z+x3e8b452f9/x93a2HxIkH44PpgeFyPD6lMAEHUdbcn8ffTP9fdTrz/8rBPCe05Iv
p9WsWF788Obl9MXJl0/PXnwONLozY747+t7x9k9l2z/4vv4kqo1//993+/vf2kC5HtwNcxXH4aOf
LRw2z9/v8WEz2LTZcpaV1TL/4c3h66ex2Xv95vjF0+PnX744PbrOm59ZVhso5UHYME/dfj768H7e
Yy5uQUydDAH9+/4eR11wHbqdfPnFF6cv3ogq/V23t++4z4620A13cSzd7O1s/77rpw+ePft916c7
O/jj2bNnT7e/t/397//M9+ibA/7s6ZNnz76PP0/kT2rz/Ts/s/0NArvziYxVEZWxbm93xsrUfnlm
rASN7Hf93u/97vvf+2Lx/e89L7+/FSXiz4Bkd/hF5mVq9Yik7fcncft9350QCu+efkr/P6BfntEv
z+iX9c4eBrFz7wEwpB9P+d9n9MfuM3yzt7Nzss0/nuJfbra3e4BvZFR7z07pj3s7O7uWJM8eCkme
nuCPp88MfW6kDeH7+26PSTX8vu+ePAAiO4LVp4zIPWC1t7O/8/+pMX3rzo2KhL7+8s23T1/RhP0e
vyvm8HbsdmPXYDVhtpdnAzJ1k1jeufOtUAM8ffP06Zcnb36fl6dPXh2f/F6nRvruyHfMd9rgJp0Y
gvsRx/6/ZUzfCtX4e5hTndGzp5jQo9e/z+s3p1/czAUMlts+P3tz+uo4tISd745uJxvb3/v4ZlWs
mrjfd9SG/swGPD/6+nh+9MF4brTBRmh1Tl5+9eT52ckt5oR0xldPzp7GR8pfuXf5PWJv4nJIwvbH
W3c+GY3vPvrs9zj8Xb/147/n7/b7/+52DD2gsSH8zGDvH9+i9/fu/PftTfTXYf5hB+9H7P1BeG52
MTtu4S2cTAjDizevv3ry+vSNb8N+3+/1po2anj4/hZsGt3TY4GmjYbEKDJ62/pHB+3/LmL62wdsU
1J18+eINzTJr3dMvXr75fX7m+MXvY9XxF2e/9+nTgPu2bgwh5U0f7u/74y9Pnh6/OX4PlA2UlwTn
xenJG8L996VhbP3++PCrV68QkrjveITxr2TIt+lL+f3k22fPn/6I6f/fMqZvqXN/K4Xps6sazUGZ
GeQlar49xEvajzI35VRevDl78/sc/b7f6jkG8Va/x52N4L9lBe/kZSh1hr9fPj19+ebbR4AifyuY
12efv5CgGh9TroR6Pj2l748iYxYgN8Z7pr0HzRLg66FnRvcjUft/45i+pRP08vTV6TOe2N/9jv37
R9P0/5YxbXQDeK5E9R12XdDA/4zop+/9Ht/65PtsDVlBBUqko986WsDoWqvbPD2gH/T01DAC1NVn
3/uZ0feZ+T77fd/GVMkA4KjeMcg6RcvQLRl8HyPaWVStdv17PwHV0bOB9xUh7rfMp5Zu3icBJp25
D6f0NhayHyfI3HXHY6YYCw7Pz17fEFhQKzS6ZWChrX+kUf7fMqavHViEPPKjCf1/y5hukcyPTvjP
mHQCppRDN4nbVFPaT8+ekpV5/TP8g/79mVPo77PT1/LL7/MzL7548+XvdfritflFY00fxIsvSQPS
mvctdYZpbt7vxKRfj3018OvC/hEf/79lTBvM3debWj+b8KO0wP+3OeM2aYHumuCAGonmCrxw9cVX
X1C2d4P+uSU7eoBUMzI3/f9udjbYl/el04dI7s8fan8dWRjm6gFx+NrKeFP+WX0CxBdPT58df/X8
DaWLX53+xFdnr06f/szv++NnX7x8fnb6NAhIwsbPkPS7iSUQAFETvP2Tx8+/Og0Xt/yBvDn9vd/c
etno8S+81QKXptq/ffzKZFZ+4e/743e8zxino+8RX37/k595h5/H28+y7fPv490hQdJ349E+txB3
zPZ5J/jsR8bs/y1j2hh/2fkayOqEmYcej0cXUWMN7QrqBwjDrVZRfyQM3xjj/EgYvo4wfLTZrnVS
ebdKq0XSZJvzajKQDUv1/P3NwbEP7cN5+Odivv9/ysPfhHfkOP6b9Fl+91v7LD9aCvp/+Zi+7lLQ
j0zwNzYFP+/Y6r1NcFeDbfBIo8rug3zS3/3WPumPlN3/y8f0I2X3cz4FP+/Y6htSdr2I42fEuSPX
/ewpL4e9/n1evzn94hb+Plpw2+dnbyh79zx0CsPvbq0lb+UQ/h7xvqPq/Gc24PnR18fzVrp8I57d
mehj7ebk5VdPnp+d3GJOSP189eTsaXyk/JV7l98j4SAZgRxtf7x155PR+O6jz36Pw9/1Wz/+e/5u
v//vbsfQAxobws8M9v7xLXp/785/395ED4nO1wx5fsTeH4LnRva+eYY8rpZUBFb/j/jfm8XAvfEj
4/b/ljF1F9B/jx5PhAkp1nu/+y3n+kdZp/93jWmjJ/M11TG++VEG6puZn593PPejoOyHMQU/79jq
GwrKfpSB+tmcwZ93XPkjZffDmIKfd2z1DSm7bmCoPPmjBNT74XkrVf71I/Sf6wTU7XJA4RB+lIC6
mW1+xN5GWw1/683C5rnj/m364cmr45Pf6/SN9H4Us4LISn355vjN2ZcvtDGT6fHvapJcMISmxc0K
MAD4IyP6/5Yx/SwkP360FvD1VTH191mURr/HUY+2P3I9boPnz7Ju/pHrcWPnP3I9/r/L3sN0v52z
0fEgNrgbL8/Evfh9fw/q5Xf93u/97vvf+2Lx/e89L7+/Fe3iZ37f34P5h178kTfx/5YxfUs8vY26
7/d4/OWbb5++ogn7PX5XzOHtOP3GrsHmqobOVO/8Hh1Gk/TPl198QS6w+rLb23fcZ0fMaTfjsv29
7Zul7me2v0FgRoYVURnf9nZEkDD+H2VDf8hjeq8xff1s6GbButNLacEtefHm9VdPXp++CRTw7/v9
r6vW8b9eJ0+/PIHzs1HHdyKE/x9L4Y+s2f+PJPX/1dbsJn3wrY6wiqv85vjVm9Pnp+DgN8efM5va
j794+eb36Xz3mAf5+58+f3r68s230dRvJcxKn/l//oh3f+7H9K2O0r05PXf85s2rH83f/1vGdAvd
w+qBFqsoWvzspozD77EpXYeZ7yzdfxy0ec+l+8e/8FbR84+Wd78xbvn/qQQMz/J7L++GPB7N0MQa
2vTMBwjDrVI0PxKGb4xxfiQMX0cYPuq/Fbx2C1sU8yEF+F34iNsx1xOGa9t6l/yX70uqmxu+qBGm
AxlxWwVS11O97ULqlsFIUvUnT4/fHIuL//3f9/t9J39Y9m8W/Tuc296yUeX/b0PiHwUeP1801Y8C
j/9vz9+PAo8f+Vq35Jb/n0rAz7Kv9aPA40fC8P+RMf3sC8PP08DjR1L3DXHoj6SuIz/CCghZNZb8
fb/Hf/2+37tjvuBY9vu3jmRvxNeGgQAuaAF6Pwj8/+e66M8/7rwpRNj6uVwXZRl52k0n3FVl95Q+
+fz0KSu73/dtkGDYdvZgSP5uskadrtViRKyal2IKAiQfiW+FI+tET/9/Txj9SFf8SFf8rOuKzagx
+r/vD34mUADO1P4/AQAA//8=
</code></pre>
<p>The options to set is <code>RegexOptions.ExplicitCapture</code>. The capture group you are looking for is <code>ELEMENTNAME</code>. If the capture group <code>ERROR</code> is not empty then there was a parsing error and the Regex stopped.</p>
<p>If you have problems reconverting it to a human-readable regex, this should help:</p>
<pre class="lang-csharp prettyprint-override"><code>static string FromBase64(string str)
{
    byte[] byteArray = Convert.FromBase64String(str);

    using (var msIn = new MemoryStream(byteArray))
    using (var msOut = new MemoryStream()) {
        using (var ds = new DeflateStream(msIn, CompressionMode.Decompress)) {
            ds.CopyTo(msOut);
        }

        return Encoding.UTF8.GetString(msOut.ToArray());
    }
}
</code></pre>
<p>If you are unsure, no, I'm NOT kidding (but perhaps I'm lying). It WILL work. I've built tons of unit tests to test it, and I have even used (part of) the <a href="http://www.w3.org/XML/Test/" rel="noreferrer">conformance tests</a>. It's a tokenizer, not a full-blown parser, so it will only split the XML into its component tokens. It won't parse/integrate DTDs.</p>
<p>Oh... if you want the source code of the regex, with some auxiliary methods:</p>
<p><a href="http://pastebin.com/hzYazFVb" rel="noreferrer">regex to tokenize an xml</a> or <a href="https://topaz.github.io/paste/#XQAAAQD5hQAAAAAAAAAUD8Q6Ijb26igjgaUO/S4VLr/Od1fatGY8ycZ79EV23K5OCMWdbg2gH+s7o5uxCPlMSN1JtgtVM2MKR6CqK1eEDhtb5JZyw5spb/FtqvAc3ed4JkSFjzVZF7RTA0u9sRtmbSyVgOdqUpqnibi1CDqHGXGOzOlBKLxSopincGbR0sbzm+mA3nrgLtwe1kqAj3MWoPyOrU8e7ipjvkI+e0LALD6uam6dq+hXtGQJ8LYSeoUpKjGW3LDV7Oh3mE3OBu9AaQF7PiSsUTC2b/AqI1rEOqBWwwkUevXnMnpPYZ+FlYhJ4zgvOyR3YStbExN6Q8h79n9w8lEqI1rr4B2xDaqTgsFd+rg0Iu3S3aaRhII9wdUaipKiEKuDujWemedqT6P+ohRi9CC/lGr8Kz5+QlErsB/97LiffPcTizNflkF8TnInJba8R0w9nhL70OX9IijnRbrHYLnEK62mliz7JFFmSWu9KqzbyrC+OkAQIi0hdmLzITt7lz8OCUKWocUyBeP3JSgXOGX/P8sw3WF6q6QBu0XmN4EgtHfcBb130ewOQ34MhCEw8q79ycePiduoP7MlbzbG5Iw8202AlrfjFp96dawcaALWOIMDGEaM7X1ZC5RFAfcpHNLu/KxctKOoyhIzYWS+LTMMPBx13L4IYXiDysJuG4acbJiDiKfla4i8Z0QGrPLvF7/1A5ufy7yLck9adE1aXZUD7yxX6qXICx+Ue6Fq+PHDslFeU6Q74LWjj/tu8CGM55EMItBrpz5EcTgeoBxNuA/vrYi/Ybm7hMscw/pYGL9RG5H+ok3OzKrWdjintjxvVV+cGNWsN/LNWC3bGp5OJaArP5OCehsMwcAQMQkNi8cpSX+cP6nRaV5nO/5borKcXufMdw8g1zmgTqul+0qISwn3MNK/Y0Qd+KgBIumvIUQT1HzLpbehbjAkYFg+PBUr4BPDAGiEN+lvtSsn3R3yFMyX0TcYe0a5dSBSMpq4P/ZCRJy+2pFLvtIMYJwph34zhLPJOoFK0LiiT+Vgt4yjHLQwGfzSug2oT5TaUAFwOWY2SeTxb5SfaxTB+DX8B+jhlX2DvEVV/EUWcoEkImMx1v9u+yuIshY69ikFaZfcrcCFPRLu6RVog+sLNgXuk/Q+OnoUuoeok367pwuiw26/byFpSFogS2DIRIG2J3agwqa0XPtcHY2j3H2niOigKaOX1oeansYqIjvGykcysm43IhAR2QEcoPKZOhi1bwSwpP98hpin+dkVJDD8f0w/ipDIMpIDRTv45VQWAzdK4yLqaauZRR76QeiAi618bOSiO0LnUYcbyRsU32v9UJ5LMZjzKo/trYrBgY/F4rZG6X+GSl03MbbQM3CHqo1iNc9voknMrNfmuSb7eGB2sNN/B5l0fk57pspZsJ2EuE1v5NtBjwrS9qMQzehoE7sh5YxbNyj9x44FSZDbV/2PXhAgkVZ63td5m8AfPngjAReF4bTvL/rlIWMCbJL6IQKAt2jH4l4wpfFm0qssBl2vdsfNXPhTzRWbB+UPJmxUBGv8YF0rd4Ol3SpuF8fF368DUP96pt96T8W56LIhPULh6yECYWX83QwMyoEvkcgeEJIEm08InYo7UWKRiQml0BTb+YOcy+V20V+k+YAZM2hEjbTNNnXqCvtmVytw1fA6OESzlpcOWzmFwKqwhRAtRJ+Z/YhQLhC7J1xdbFc3cG9hihArqtMRXCCFLcf24zl5rhtV9NJRZdn56s2qspoMtk8m+vGXaLFKdt3j8O5KEaPCILeUbXLS6gtm+ByiGuIF4GWAWcstCh0IQ5j+0J/+5SRp27y/Q0kvZNhD/HrqNmONDE6h7qaE6fKrhrmCLo8XcM59eiEeJuO/KWSDVbpwaDhrx+DS0ngI5TeWmAliRXYUISI/B+hhjFwawuXlK1FAm0Ohyf6XBo4dwoU/SYOHva8wB2qiPlVCvRvs7vK9FkWQjzNw0v/sDHy+nd49LiIdJkvBPsYS72H/E7kLt7P7WVJgpENY4AqXXGtZ6/L5lcByXgFxDgZbiWMKf1GCfb5QNLauPHZBjxI45JvZsDlG3sUaHwnRyYLiDE+ly+w53l2GgVX4wpPQ1JPjCIvLJ8fmKy4B5HOC5uJYTfUyjAeKP5aIloVVGESb8SGbXRfcme11BZmPyBvjivWZ8kABDh6aKGZdUZCvMnlbZnwKYUWl1ZSFi5AMlw0nEu9pFy5h/AIE+yRTioJ9VYn7ZC4njk5p7V7g+ynr8xGDRAcwLQPVUuCVCDVDSx1eGfWa6IT9G6aVHA1+SHx+sPvHNmWCMYpYWPY5b6l5DYXlTPqChQBwMxcGQnusdNEsEvQYV4FBJhYjgLMxfjBoLPPvysNmpg+qItxnBaDZgMEFa4I3Ek1e7f412UaMloHzTKuzotNQE3quvOH0/9zORWQ=" rel="noreferrer">the full plain regex</a></p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2011-03-08T13:30:46"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="5233151">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/5233151"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-5233151" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/5233151/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2021-11-10 00:06:17Z' class='relativetime'>Nov 10, 2021 at 0:06</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Mar 8, 2011 at 13:30. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-5233151" href="/posts/5233151/revisions" title="show revision history for this post">
        13 revs, 11 users 68%<br><a href="/users/613130">xanatos</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">26</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-5233151" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="5233151" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="21"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-5890472" class="comment js-comment " data-comment-id="5890472" data-comment-owner-id="446591" data-comment-score="67">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">67</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">not-sure-if-serious.jpg -- hopefully this is brilliant satire</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/446591/brad-mace"
                            title="26,775 reputation"
                            class="comment-user">Brad Mace</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-03-08 14:53:31Z, License: CC BY-SA 2.5' class='relativetime-clean'>Mar 8, 2011 at 14:53</span></span>
            </div>
        </div>
    </li>
    <li id="comment-5890952" class="comment js-comment " data-comment-id="5890952" data-comment-owner-id="399649" data-comment-score="83">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">83</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Good Lord, it&#39;s massive. My biggest question is why? You realize that all modern languages have XML parsers, right? You can do all that in like 3 lines and be sure it&#39;ll work. Furthermore, do you also realize that pure regex is <b>provably</b> unable to do certain things? Unless you&#39;ve created a hybrid regex/imperative code parser, but it doesn&#39;t look like you have. Can you compress random data as well?</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/399649/justin-morgan"
                            title="29,345 reputation"
                            class="comment-user">Justin Morgan</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-03-08 15:23:45Z, License: CC BY-SA 2.5' class='relativetime-clean'>Mar 8, 2011 at 15:23</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-5891077" class="comment js-comment " data-comment-id="5891077" data-comment-owner-id="613130" data-comment-score="142">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">142</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Justin I don&#39;t need a reason. It could be done (and it wasn&#39;t illegal/immoral), so I have done it. There are no limitations to the mind except those we acknowledge (Napoleon Hill)... Modern languages can parse XML? Really? And I thought that THAT was illegal! :-)</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/613130/xanatos"
                            title="107,741 reputation"
                            class="comment-user">xanatos</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-03-08 15:31:34Z, License: CC BY-SA 2.5' class='relativetime-clean'>Mar 8, 2011 at 15:31</span></span>
            </div>
        </div>
    </li>
    <li id="comment-5893435" class="comment js-comment " data-comment-id="5893435" data-comment-owner-id="399649" data-comment-score="91">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">91</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Sir, I&#39;m convinced. I&#39;m going to use this code as part of the kernel for my perpetual-motion machine--can you believe those fools at the patent office keep rejecting my application? Well, I&#39;ll show them. I&#39;ll show them all!</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/399649/justin-morgan"
                            title="29,345 reputation"
                            class="comment-user">Justin Morgan</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-03-08 17:55:54Z, License: CC BY-SA 2.5' class='relativetime-clean'>Mar 8, 2011 at 17:55</span></span>
            </div>
        </div>
    </li>
    <li id="comment-11735313" class="comment js-comment " data-comment-id="11735313" data-comment-owner-id="244811" data-comment-score="41">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">41</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">No, nothing is bug free: 1) All programs contain at least one bug. 2) All programs contain at least one line of unnecessary source code. 3) By #1 and #2 and using logical induction, it&#39;s a simple matter to prove that any program can be reduced to a single line of code with a bug. (from Learning Perl)</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/244811/scott-weaver"
                            title="7,010 reputation"
                            class="comment-user">Scott Weaver</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-02-16 00:53:34Z, License: CC BY-SA 3.0' class='relativetime-clean'>Feb 16, 2012 at 0:53</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-5233151" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>21</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="2263520"></a>
<div id="answer-2263520" class="answer js-answer" data-answerid="2263520" data-parentid="1732348" data-score="315" data-position-on-page="7" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="2263520">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="315">
            315
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-2263520"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="2263520"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2263520/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>In shell, you can parse <a href="https://en.wikipedia.org/wiki/HTML" rel="noreferrer">HTML</a> using <a href="https://en.wikipedia.org/wiki/Sed" rel="noreferrer">sed</a>:</p>

<ol>
<li><a href="http://sed.sourceforge.net/grabbag/scripts/turing.sed" rel="noreferrer">Turing.sed</a></li>
<li>Write HTML parser (homework)</li>
<li>???</li>
<li>Profit!</li>
</ol>

<hr>

<p>Related (why you shouldn't use regex match):</p>

<ul>
<li><a href="https://blog.codinghorror.com/if-you-like-regular-expressions-so-much-why-dont-you-marry-them/" rel="noreferrer">If You Like Regular Expressions So Much, Why Don't You Marry Them?</a></li>
<li><a href="https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/" rel="noreferrer">Regular Expressions: Now You Have Two Problems</a></li>
<li><a href="http://danlec.com/blog/hacking-stackoverflow-com-s-html-sanitizer" rel="noreferrer">Hacking stackoverflow.com's HTML sanitizer</a></li>
</ul>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2010-02-15T00:55:24"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="2263520">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/2263520"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-2263520" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/2263520/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2019-04-23 16:44:36Z' class='relativetime'>Apr 23, 2019 at 16:44</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Feb 15, 2010 at 0:55. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2263520" href="/posts/2263520/revisions" title="show revision history for this post">
        10 revs, 7 users 43%<br><a href="/users/55075">kenorb</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">7</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-2263520" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="2263520" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="2"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-54010279" class="comment js-comment " data-comment-id="54010279" data-comment-owner-id="2157640" data-comment-score="3">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I’m afraid you did not get the joke, @kenorb. Please, read the question and the accepted answer once more. This is not about HTML parsing tools in general, nor about HTML parsing shell tools, it’s about parsing HTML via regexes.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/2157640/palec"
                            title="12,013 reputation"
                            class="comment-user">Palec</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2015-10-13 08:12:01Z, License: CC BY-SA 3.0' class='relativetime-clean'>Oct 13, 2015 at 8:12</span></span>
            </div>
        </div>
    </li>
    <li id="comment-73090810" class="comment js-comment " data-comment-id="73090810" data-comment-owner-id="2157640" data-comment-score="2">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">No, @Abdul. It is completely, provably (in the mathematical sense) impossible.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/2157640/palec"
                            title="12,013 reputation"
                            class="comment-user">Palec</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2017-03-24 13:24:19Z, License: CC BY-SA 3.0' class='relativetime-clean'>Mar 24, 2017 at 13:24</span></span>
            </div>
        </div>
    </li>
    <li id="comment-73093275" class="comment js-comment " data-comment-id="73093275" data-comment-owner-id="2157640" data-comment-score="5">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">5</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Yes, that answer summarizes it well, @Abdul. Note that, however, regex implementations are not really <i>regular</i> expressions in the mathematical sense -- they have constructs that make them stronger, often Turing-complete (equivalent to Type 0 grammars). The argument breaks with this fact, but is still somewhat valid in the sense that regexes were never meant to be capable of doing such a job, though.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/2157640/palec"
                            title="12,013 reputation"
                            class="comment-user">Palec</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2017-03-24 14:24:35Z, License: CC BY-SA 3.0' class='relativetime-clean'>Mar 24, 2017 at 14:24</span></span>
            </div>
        </div>
    </li>
    <li id="comment-73093363" class="comment js-comment " data-comment-id="73093363" data-comment-owner-id="2157640" data-comment-score="2">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">And by the way, the joke I referred to was the content of this answer before kenorb&#39;s (radical) edits, specifically revision 4, @Abdul.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/2157640/palec"
                            title="12,013 reputation"
                            class="comment-user">Palec</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2017-03-24 14:26:48Z, License: CC BY-SA 3.0' class='relativetime-clean'>Mar 24, 2017 at 14:26</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-86127667" class="comment js-comment " data-comment-id="86127667" data-comment-owner-id="11906" data-comment-score="10">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">10</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">The funny thing is that OP never asked to parse html using regex. He asked to match text (which happens to be HTML) using regex. Which is perfectly reasonable.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/11906/paralife"
                            title="6,066 reputation"
                            class="comment-user">Paralife</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2018-03-29 15:29:49Z, License: CC BY-SA 3.0' class='relativetime-clean'>Mar 29, 2018 at 15:29</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-2263520" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>2</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="7564061"></a>
<div id="answer-7564061" class="answer js-answer" data-answerid="7564061" data-parentid="1732348" data-score="289" data-position-on-page="8" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="7564061">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="289">
            289
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-7564061"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="7564061"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/7564061/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>I agree that the right tool to parse XML and <em>especially HTML</em> is a parser and not a regular expression engine. However, like others have pointed out, sometimes using a regex is quicker, easier, and gets the job done if you know the data format.</p>

<p>Microsoft actually has a section of <a href="https://learn.microsoft.com/dotnet/standard/base-types/best-practices" rel="noreferrer">Best Practices for Regular Expressions in the .NET Framework</a> and specifically talks about <a href="https://learn.microsoft.com/dotnet/standard/base-types/best-practices#consider-the-input-source" rel="noreferrer">Consider[ing] the Input Source</a>.</p>

<p>Regular Expressions do have limitations, but have you considered the following?</p>

<p>The .NET framework is unique when it comes to regular expressions in that it supports <a href="https://learn.microsoft.com/dotnet/standard/base-types/grouping-constructs-in-regular-expressions#balancing_group_definition" rel="noreferrer">Balancing Group Definitions</a>.</p>

<ul>
<li>See <a href="https://weblogs.asp.net/whaggard/377025" rel="noreferrer">Matching Balanced Constructs with .NET Regular Expressions</a></li>
<li>See <a href="https://learn.microsoft.com/archive/blogs/bclteam/net-regular-expressions-regex-and-balanced-matching-ryan-byington" rel="noreferrer">.NET Regular Expressions: Regex and Balanced Matching</a></li>
<li>See Microsoft's docs on <a href="https://learn.microsoft.com/dotnet/standard/base-types/grouping-constructs-in-regular-expressions#balancing_group_definition" rel="noreferrer">Balancing Group Definitions</a></li>
</ul>

<p>For this reason, I believe you CAN parse XML using regular expressions. Note however, that it <strong>must be valid XML</strong> (<em>browsers are very forgiving of HTML and allow bad XML syntax inside HTML</em>). This is possible since the "Balancing Group Definition" will allow the regular expression engine to act as a PDA.</p>

<p>Quote from article 1 cited above:</p>

<blockquote>
  <p><strong>.NET Regular Expression Engine</strong></p>
  
  <p>As described above properly balanced constructs cannot be described by
  a regular expression. However, the .NET regular expression engine
  provides a few constructs that allow balanced constructs to be
  recognized. </p>
  
  <ul>
  <li><code>(?&lt;group&gt;)</code> - pushes the captured result on the capture stack with
  the name group.</li>
  <li><code>(?&lt;-group&gt;)</code> - pops the top most capture with the name group off the
  capture stack.</li>
  <li><code>(?(group)yes|no)</code> - matches the yes part if there exists a group
  with the name group otherwise matches no part.</li>
  </ul>
  
  <p>These constructs allow for a .NET regular expression to emulate a
  restricted PDA by essentially allowing simple versions of the stack
  operations: push, pop and empty. The simple operations are pretty much
  equivalent to increment, decrement and compare to zero respectively.
  This allows for the .NET regular expression engine to recognize a
  subset of the context-free languages, in particular the ones that only
  require a simple counter. This in turn allows for the non-traditional
  .NET regular expressions to recognize individual properly balanced
  constructs.</p>
</blockquote>

<p>Consider the following regular expression:</p>

<pre class="lang-none prettyprint-override"><code>(?=&lt;ul\s+id="matchMe"\s+type="square"\s*&gt;)
(?&gt;
   &lt;!-- .*? --&gt;                  |
   &lt;[^&gt;]*/&gt;                      |
   (?&lt;opentag&gt;&lt;(?!/)[^&gt;]*[^/]&gt;)  |
   (?&lt;-opentag&gt;&lt;/[^&gt;]*[^/]&gt;)     |
   [^&lt;&gt;]*
)*
(?(opentag)(?!))
</code></pre>

<p>Use the flags:</p>

<ul>
<li>Singleline</li>
<li>IgnorePatternWhitespace (not necessary if you collapse regex and remove all whitespace)</li>
<li>IgnoreCase (not necessary)</li>
</ul>

<h2>Regular Expression Explained (inline)</h2>

<pre class="lang-none prettyprint-override"><code>(?=&lt;ul\s+id="matchMe"\s+type="square"\s*&gt;) # match start with &lt;ul id="matchMe"...
(?&gt;                                        # atomic group / don't backtrack (faster)
   &lt;!-- .*? --&gt;                 |          # match xml / html comment
   &lt;[^&gt;]*/&gt;                     |          # self closing tag
   (?&lt;opentag&gt;&lt;(?!/)[^&gt;]*[^/]&gt;) |          # push opening xml tag
   (?&lt;-opentag&gt;&lt;/[^&gt;]*[^/]&gt;)    |          # pop closing xml tag
   [^&lt;&gt;]*                                  # something between tags
)*                                         # match as many xml tags as possible
(?(opentag)(?!))                           # ensure no 'opentag' groups are on stack
</code></pre>

<p>You can try this at <a href="http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx" rel="noreferrer">A Better .NET Regular Expression Tester</a>.</p>

<p>I used the sample source of:</p>

<pre><code>&lt;html&gt;
&lt;body&gt;
&lt;div&gt;
   &lt;br /&gt;
   &lt;ul id="matchMe" type="square"&gt;
      &lt;li&gt;stuff...&lt;/li&gt;
      &lt;li&gt;more stuff&lt;/li&gt;
      &lt;li&gt;
          &lt;div&gt;
               &lt;span&gt;still more&lt;/span&gt;
               &lt;ul&gt;
                    &lt;li&gt;Another &amp;gt;ul&amp;lt;, oh my!&lt;/li&gt;
                    &lt;li&gt;...&lt;/li&gt;
               &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/li&gt;
   &lt;/ul&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>This found the match:</p>

<pre><code>   &lt;ul id="matchMe" type="square"&gt;
      &lt;li&gt;stuff...&lt;/li&gt;
      &lt;li&gt;more stuff&lt;/li&gt;
      &lt;li&gt;
          &lt;div&gt;
               &lt;span&gt;still more&lt;/span&gt;
               &lt;ul&gt;
                    &lt;li&gt;Another &amp;gt;ul&amp;lt;, oh my!&lt;/li&gt;
                    &lt;li&gt;...&lt;/li&gt;
               &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/li&gt;
   &lt;/ul&gt;
</code></pre>

<p>although it actually came out like this:</p>

<pre><code>&lt;ul id="matchMe" type="square"&gt;           &lt;li&gt;stuff...&lt;/li&gt;           &lt;li&gt;more stuff&lt;/li&gt;           &lt;li&gt;               &lt;div&gt;                    &lt;span&gt;still more&lt;/span&gt;                    &lt;ul&gt;                         &lt;li&gt;Another &amp;gt;ul&amp;lt;, oh my!&lt;/li&gt;                         &lt;li&gt;...&lt;/li&gt;                    &lt;/ul&gt;               &lt;/div&gt;           &lt;/li&gt;        &lt;/ul&gt;
</code></pre>

<p>Lastly, I really enjoyed Jeff Atwood's article:  <a href="https://blog.codinghorror.com/parsing-html-the-cthulhu-way/" rel="noreferrer">Parsing Html The Cthulhu Way</a>. Funny enough, it cites the answer to this question that currently has over 4k votes.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2011-09-27T04:01:04"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="7564061">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/7564061"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-7564061" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info user-hover">
    <div class="user-action-time">
        <a href="/posts/7564061/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2020-02-23 04:43:47Z' class='relativetime'>Feb 23, 2020 at 4:43</span></a>
    </div>
    <div class="user-gravatar32">
        <a href="/users/4415734/callum-watkins"><div class="gravatar-wrapper-32"><img src="https://i.stack.imgur.com/x6QKy.png?s=64&amp;g=1" alt="Callum Watkins&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
    </div>
    <div class="user-details">
        <a href="/users/4415734/callum-watkins">Callum Watkins</a>
        <div class="-flair">
            <span class="reputation-score" title="reputation score " dir="ltr">2,704</span><span title="4 gold badges" aria-hidden="true"><span class="badge1"></span><span class="badgecount">4</span></span><span class="v-visible-sr">4 gold badges</span><span title="31 silver badges" aria-hidden="true"><span class="badge2"></span><span class="badgecount">31</span></span><span class="v-visible-sr">31 silver badges</span><span title="48 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">48</span></span><span class="v-visible-sr">48 bronze badges</span>
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info ">
    <div class="user-action-time">
        answered <span title='2011-09-27 04:01:04Z' class='relativetime'>Sep 27, 2011 at 4:01</span>
    </div>
    <div class="user-gravatar32">
        <a href="/users/590956/sam"><div class="gravatar-wrapper-32"><img src="https://i.stack.imgur.com/y06xx.jpg?s=64&amp;g=1" alt="Sam&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
    </div>
    <div class="user-details" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <a href="/users/590956/sam">Sam</a><span class="d-none" itemprop="name">Sam</span>
        <div class="-flair">
            <span class="reputation-score" title="reputation score 26,579" dir="ltr">26.6k</span><span title="12 gold badges" aria-hidden="true"><span class="badge1"></span><span class="badgecount">12</span></span><span class="v-visible-sr">12 gold badges</span><span title="72 silver badges" aria-hidden="true"><span class="badge2"></span><span class="badgecount">72</span></span><span class="v-visible-sr">72 silver badges</span><span title="100 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">100</span></span><span class="v-visible-sr">100 bronze badges</span>
        </div>
    </div>
</div>


            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">5</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-7564061" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="7564061" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-11457016" class="comment js-comment " data-comment-id="11457016" data-comment-owner-id="76337" data-comment-score="19">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">19</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy"><code>System.Text</code> is not part of C#. It&#39;s part of .NET.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/76337/john-saunders"
                            title="159,726 reputation"
                            class="comment-user">John Saunders</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-02-02 19:07:53Z, License: CC BY-SA 3.0' class='relativetime-clean'>Feb 2, 2012 at 19:07</span></span>
            </div>
        </div>
    </li>
    <li id="comment-14956273" class="comment js-comment " data-comment-id="14956273" data-comment-owner-id="1344461" data-comment-score="8">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">8</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">In the first line of your regex (<code>(?=&lt;ul\s*id=&quot;matchMe&quot;\s*type=&quot;square&quot;\s*&gt;) # match start with &lt;ul id=&quot;matchMe&quot;...</code>), in between &quot;&lt;ul&quot; and &quot;id&quot; should be <code>\s+</code>, not <code>\s*</code>, unless you want it to match &lt;ulid=... ;)</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/1344461/c0deh4cker"
                            title="3,927 reputation"
                            class="comment-user">C0deH4cker</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-07-06 02:49:08Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 6, 2012 at 2:49</span></span>
            </div>
        </div>
    </li>
    <li id="comment-14982109" class="comment js-comment " data-comment-id="14982109" data-comment-owner-id="590956" data-comment-score="0">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@C0deH4cker You are correct, the expression should have <code>\s+</code> instead of <code>\s*</code>.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/590956/sam"
                            title="26,579 reputation"
                            class="comment-user">Sam</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-07-06 22:33:05Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 6, 2012 at 22:33</span></span>
            </div>
        </div>
    </li>
    <li id="comment-28164133" class="comment js-comment " data-comment-id="28164133" data-comment-owner-id="1455622" data-comment-score="4">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">4</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Not that I really understand it, but I think your regex fails on <code>&lt;img src=&quot;images&#47;pic.jpg&quot; &#47;&gt;</code></span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/1455622/scheintod"
                            title="7,785 reputation"
                            class="comment-user">Scheintod</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2013-09-27 17:05:13Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 27, 2013 at 17:05</span></span>
            </div>
        </div>
    </li>
    <li id="comment-28167413" class="comment js-comment " data-comment-id="28167413" data-comment-owner-id="590956" data-comment-score="3">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Scheintod Thank you for the comment.  I updated the code.  The previous expression failed for self closing tags that had a <code>&#47;</code> somewhere inside which failed for your <code>&lt;img src=&quot;images&#47;pic.jpg&quot; &#47;&gt;</code> html.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/590956/sam"
                            title="26,579 reputation"
                            class="comment-user">Sam</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2013-09-27 19:00:25Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 27, 2013 at 19:00</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-7564061" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1732595"></a>
<div id="answer-1732595" class="answer js-answer" data-answerid="1732595" data-parentid="1732348" data-score="265" data-position-on-page="9" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1732595">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="265">
            265
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1732595"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1732595"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732595/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>I suggest using <a href="http://querypath.org/" rel="noreferrer">QueryPath</a> for parsing XML and HTML in PHP.  It's basically much the same syntax as jQuery, only it's on the server side.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-13T23:44:50"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1732595">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1732595"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1732595" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732595/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2015-05-12 18:54:20Z' class='relativetime'>May 12, 2015 at 18:54</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732595" href="/posts/1732595/revisions" title="show revision history for this post">
        4 revs, 4 users 57%<br><a href="/users/9143">John Fiala</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">4</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1732595" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="1732595" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-29262125" class="comment js-comment " data-comment-id="29262125" data-comment-owner-id="257182" data-comment-score="9">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">9</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Kyle—jQuery does not parse XML, it uses the client&#39;s built–in parser (if there is one). Therefore you do not need jQuery to do it, but as little as two lines of <a href="https://developer.mozilla.org/en-US/docs/Parsing_and_serializing_XML" rel="nofollow noreferrer">plain old JavaScript</a>. If there is no built–in parser, jQuery will not help.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/257182/robg"
                            title="138,016 reputation"
                            class="comment-user">RobG</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2013-10-31 06:25:27Z, License: CC BY-SA 3.0' class='relativetime-clean'>Oct 31, 2013 at 6:25</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-40656661" class="comment js-comment " data-comment-id="40656661" data-comment-owner-id="510036" data-comment-score="2">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@RobG Actually jQuery uses the DOM, not the built-in parser.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/510036/qix-monica-was-mistreated"
                            title="13,730 reputation"
                            class="comment-user">Qix - MONICA WAS MISTREATED</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2014-09-22 03:49:04Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 22, 2014 at 3:49</span></span>
            </div>
        </div>
    </li>
    <li id="comment-40657671" class="comment js-comment " data-comment-id="40657671" data-comment-owner-id="257182" data-comment-score="12">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">12</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Qix—you&#39;d better tell the authors of the documentation then: &quot;<i>jQuery.parseXML uses the native parsing function of the browser…</i>&quot;. Source: <a href="http://api.jquery.com/jQuery.parseXML/" rel="nofollow noreferrer"><i>jQuery.parseXML()</i></a></span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/257182/robg"
                            title="138,016 reputation"
                            class="comment-user">RobG</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2014-09-22 05:01:30Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 22, 2014 at 5:01</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-60351141" class="comment js-comment " data-comment-id="60351141" data-comment-owner-id="8681" data-comment-score="6">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">6</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Having come here from the meme question (<a href="http://meta.stackexchange.com/questions/19478/the-many-memes-of-meta/19479#19479" title="the many memes of meta">meta.stackexchange.com/questions/19478/the-many-memes-of-meta/&hellip;</a>), I love that one of the answers is &#39;Use jQuery&#39;</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/8681/jorn"
                            title="17,801 reputation"
                            class="comment-user">Jorn</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-04-01 21:09:45Z, License: CC BY-SA 3.0' class='relativetime-clean'>Apr 1, 2016 at 21:09</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1732595" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="2146912"></a>
<div id="answer-2146912" class="answer js-answer" data-answerid="2146912" data-parentid="1732348" data-score="233" data-position-on-page="10" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="2146912">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="233">
            233
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-2146912"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="2146912"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2146912/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>While the answers that you can't parse HTML with regexes are correct, they don't apply here. The OP just wants to parse one HTML tag with regexes, and that is something that can be done with a regular expression.</p>

<p>The suggested regex is wrong, though:</p>

<pre><code>&lt;([a-z]+) *[^/]*?&gt;
</code></pre>

<p>If you add something to the regex, by backtracking it can be forced to match silly things like <code>&lt;a &gt;&gt;</code>, <code>[^/]</code> is too permissive. Also note that <code>&lt;space&gt;*[^/]*</code> is redundant, because the <code>[^/]*</code> can also match spaces.</p>

<p>My suggestion would be</p>

<pre><code>&lt;([a-z]+)[^&gt;]*(?&lt;!/)&gt;
</code></pre>

<p>Where <code>(?&lt;! ... )</code> is (in Perl regexes) the negative look-behind. It reads "a &lt;, then a word, then anything that's not a >, the last of which may not be a /, followed by >".</p>

<p>Note that this allows things like <code>&lt;a/ &gt;</code> (just like the original regex), so if you want something more restrictive, you need to build a regex to match attribute pairs separated by spaces.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2010-01-27T12:54:35"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="2146912">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/2146912"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
                   data-se-share-sheet-license-name="CC BY-SA 2.5"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-2146912" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/2146912/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title='2010-01-27 12:54:35Z' class='relativetime'>Jan 27, 2010 at 12:54</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jan 27, 2010 at 12:54. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2146912" href="/posts/2146912/revisions" title="show revision history for this post">
        moritz
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">6</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-2146912" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="2146912" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="1"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-16545748" class="comment js-comment " data-comment-id="16545748" data-comment-owner-id="423105" data-comment-score="31">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">31</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">+1 for noting that the question is not about parsing full (X)HTML, it&#39;s about matching (X)HTML open tags.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/423105/larsh"
                            title="26,946 reputation"
                            class="comment-user">LarsH</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2012-09-08 02:26:22Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 8, 2012 at 2:26</span></span>
            </div>
        </div>
    </li>
    <li id="comment-46771251" class="comment js-comment " data-comment-id="46771251" data-comment-owner-id="2543666" data-comment-score="11">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">11</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Something else most of the answers seem to ignore, is that an HTML parser can very well use regular expressions in its implementation for parts of HTML, and I would be surprised if most parsers didn&#39;t do this.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/2543666/thayne"
                            title="6,421 reputation"
                            class="comment-user">Thayne</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2015-03-26 19:15:04Z, License: CC BY-SA 3.0' class='relativetime-clean'>Mar 26, 2015 at 19:15</span></span>
            </div>
        </div>
    </li>
    <li id="comment-55471750" class="comment js-comment " data-comment-id="55471750" data-comment-owner-id="3476849" data-comment-score="2">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Thayne Exactly. When parsing individual tags, a regular expression is the right tool for the job. It is quite ridiculous that one has to scroll halfway down the page to find a reasonable answer. The accepted answer is incorrect because it mixes up lexing and parsing.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/3476849/kasperd"
                            title="1,922 reputation"
                            class="comment-user">kasperd</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2015-11-22 10:26:25Z, License: CC BY-SA 3.0' class='relativetime-clean'>Nov 22, 2015 at 10:26</span></span>
            </div>
        </div>
    </li>
    <li id="comment-61105461" class="comment js-comment " data-comment-id="61105461" data-comment-owner-id="3829420" data-comment-score="4">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">4</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">The answer given here will fail when an attribute value contains a &#39;&gt;&#39; or &#39;/&#39; character.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/3829420/martin-l"
                            title="986 reputation"
                            class="comment-user">Martin L</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-04-21 08:14:04Z, License: CC BY-SA 3.0' class='relativetime-clean'>Apr 21, 2016 at 8:14</span></span>
            </div>
        </div>
    </li>
    <li id="comment-77757983" class="comment js-comment " data-comment-id="77757983" data-comment-owner-id="7488" data-comment-score="1">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">1</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">This will work incorrectly on HTML containing comments or CData sections.  It will also not work correctly if a quoted attribute contains a <code>&gt;</code> character. I agree what OP suggest <i>can</i> be done with a regex, but the one presented here is far to simplistic.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/7488/jacquesb"
                            title="41,058 reputation"
                            class="comment-user">JacquesB</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2017-07-30 10:14:41Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 30, 2017 at 10:14</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-2146912" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>1</b> more comment</a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1732395"></a>
<div id="answer-1732395" class="answer js-answer" data-answerid="1732395" data-parentid="1732348" data-score="191" data-position-on-page="11" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1732395">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="191">
            191
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1732395"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1732395"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732395/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>Try:</p>

<pre><code>&lt;([^\s]+)(\s[^&gt;]*?)?(?&lt;!/)&gt;
</code></pre>

<p>It is similar to yours, but the last <code>&gt;</code> must not be after a slash, and also accepts <code>h1</code>.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-13T22:50:48"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1732395">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1732395"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
                   data-se-share-sheet-license-name="CC BY-SA 2.5"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1732395" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732395/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2009-11-25 21:12:04Z' class='relativetime'>Nov 25, 2009 at 21:12</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732395" href="/posts/1732395/revisions" title="show revision history for this post">
        3 revs, 2 users 77%<br><a href="/users/7586">Kobi</a>

        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">6</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1732395" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="1732395" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="1"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-1612303" class="comment js-comment " data-comment-id="1612303" data-comment-owner-id="31582" data-comment-score="114">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">114</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">&lt;a href=&quot;foo&quot; title=&quot;5&gt;3&quot;&gt; Oops &lt;/a&gt;</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/31582/gareth"
                            title="127,913 reputation"
                            class="comment-user">Gareth</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2009-11-13 23:11:39Z, License: CC BY-SA 2.5' class='relativetime-clean'>Nov 13, 2009 at 23:11</span></span>
            </div>
        </div>
    </li>
    <li id="comment-1612577" class="comment js-comment " data-comment-id="1612577" data-comment-owner-id="18936" data-comment-score="67">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">67</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy"><code>&gt;</code> is valid in an attribute value. Indeed, in the ‘canonical XML’ serialisation you must not use <code>&amp;gt;</code>. (Which isn&#39;t entirely relevant, except to emphasise that <code>&gt;</code> in an attribute value is not at all an unusual thing.)</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/18936/bobince"
                            title="520,261 reputation"
                            class="comment-user">bobince</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2009-11-14 00:15:33Z, License: CC BY-SA 2.5' class='relativetime-clean'>Nov 14, 2009 at 0:15</span></span>
            </div>
        </div>
    </li>
    <li id="comment-6710778" class="comment js-comment " data-comment-id="6710778" data-comment-owner-id="260080" data-comment-score="5">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">5</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@Kobi: what does the exlamation mark (the one you placed tpward the end) mean in a regexp?</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/260080/marco-demaio"
                            title="32,860 reputation"
                            class="comment-user">Marco Demaio</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-04-30 17:16:11Z, License: CC BY-SA 3.0' class='relativetime-clean'>Apr 30, 2011 at 17:16</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-6710897" class="comment js-comment " data-comment-id="6710897" data-comment-owner-id="260080" data-comment-score="6">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">6</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@bobince: are u sure? I don&#39;t understand anymore, so is this valid HTML too: <code>&lt;div title=&quot;this tag is a &lt;div&gt;&lt;&#47;div&gt;&quot;&gt;hello&lt;&#47;div&gt;</code></span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/260080/marco-demaio"
                            title="32,860 reputation"
                            class="comment-user">Marco Demaio</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-04-30 17:31:15Z, License: CC BY-SA 3.0' class='relativetime-clean'>Apr 30, 2011 at 17:31</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-67296534" class="comment js-comment " data-comment-id="67296534" data-comment-owner-id="317052" data-comment-score="3">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@MarcoDemaio - <code>&gt;</code> does not have to be escaped in an attribute value, but <code>&lt;</code> does. So this is would be valid HTML: <code>&lt;div title=&quot;this tag is a &amp;lt;div&gt;&amp;lt;&#47;div&gt;&quot;&gt;hello&lt;&#47;div&gt;</code></span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/317052/daniel-haley"
                            title="49,857 reputation"
                            class="comment-user">Daniel Haley</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-10-12 22:11:04Z, License: CC BY-SA 3.0' class='relativetime-clean'>Oct 12, 2016 at 22:11</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1732395" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>1</b> more comment</a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="10633717"></a>
<div id="answer-10633717" class="answer js-answer" data-answerid="10633717" data-parentid="1732348" data-score="191" data-position-on-page="12" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="10633717">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="191">
            191
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-10633717"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="10633717"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/10633717/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>Sun Tzu, an ancient Chinese strategist, general, and philosopher, said:</p>

<blockquote>
  <p>It is said that if you know your enemies and know yourself, you can win a hundred battles without a single loss.
  If you only know yourself, but not your opponent, you may win or may lose.
  If you know neither yourself nor your enemy, you will always endanger yourself.</p>
</blockquote>

<p>In this case your enemy is HTML and you are either yourself or regex.  You might even be Perl with irregular regex. Know HTML.  Know yourself.</p>

<p>I have composed a haiku describing the nature of HTML.</p>

<pre><code>HTML has
complexity exceeding
regular language.
</code></pre>

<p>I have also composed a haiku describing the nature of regex in Perl.</p>

<pre><code>The regex you seek
is defined within the phrase
&lt;([a-zA-Z]+)(?:[^&gt;]*[^/]*)?&gt;
</code></pre>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2012-05-17T10:13:03"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="10633717">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/10633717"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-10633717" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/10633717/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2013-10-05 04:52:53Z' class='relativetime'>Oct 5, 2013 at 4:52</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of May 17, 2012 at 10:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-10633717" href="/posts/10633717/revisions" title="show revision history for this post">
        2 revs, 2 users 98%<br><a href="/users/863553">cytinus</a>

        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">0</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-10633717" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="10633717" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-10633717" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1737662"></a>
<div id="answer-1737662" class="answer js-answer" data-answerid="1737662" data-parentid="1732348" data-score="160" data-position-on-page="13" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1737662">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="160">
            160
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1737662"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1737662"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1737662/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<pre><code>&lt;?php
$selfClosing = explode(',', 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed');

$html = '
&lt;p&gt;&lt;a href="#"&gt;foo&lt;/a&gt;&lt;/p&gt;
&lt;hr/&gt;
&lt;br/&gt;
&lt;div&gt;name&lt;/div&gt;';

$dom = new DOMDocument();
$dom-&gt;loadHTML($html);
$els = $dom-&gt;getElementsByTagName('*');
foreach ( $els as $el ) {
    $nodeName = strtolower($el-&gt;nodeName);
    if ( !in_array( $nodeName, $selfClosing ) ) {
        var_dump( $nodeName );
    }
}
</code></pre>

<p>Output:</p>

<pre><code>string(4) "html"
string(4) "body"
string(1) "p"
string(1) "a"
string(3) "div"
</code></pre>

<p>Basically just define the element node names that are self closing, load the whole html string into a DOM library, grab all elements, loop through and filter out ones which aren't self closing and operate on them.</p>

<p>I'm sure you already know by now that you shouldn't use regex for this purpose.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-15T14:37:06"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1737662">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1737662"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
                   data-se-share-sheet-license-name="CC BY-SA 2.5"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1737662" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1737662/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2009-11-15 14:44:04Z' class='relativetime'>Nov 15, 2009 at 14:44</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1737662" href="/posts/1737662/revisions" title="show revision history for this post">
        2 revs<br><a href="/users/145190">meder</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">1</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1737662" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="1737662" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-1618096" class="comment js-comment " data-comment-id="1618096" data-comment-owner-id="145190" data-comment-score="1">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">1</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">If you&#39;re dealing with real XHTML then append getElementsByTagName with <code>NS</code> and specify the namespace.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/145190/meder-omuraliev"
                            title="180,288 reputation"
                            class="comment-user">meder omuraliev</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2009-11-15 14:39:44Z, License: CC BY-SA 2.5' class='relativetime-clean'>Nov 15, 2009 at 14:39</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1737662" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1745488"></a>
<div id="answer-1745488" class="answer js-answer" data-answerid="1745488" data-parentid="1732348" data-score="151" data-position-on-page="14" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1745488">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="151">
            151
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1745488"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1745488"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1745488/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>I don't know your exact need for this, but if you are also using .NET, couldn't you use <a href="http://www.codeplex.com/htmlagilitypack" rel="noreferrer">Html Agility Pack</a>?</p>

<p>Excerpt:</p>

<blockquote>
  <p><em>It is a .NET code library that allows
  you to parse "out of the web" HTML
  files. The parser is very tolerant
  with "real world" malformed HTML.</em></p>
</blockquote>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-16T23:15:03"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1745488">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1745488"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
                   data-se-share-sheet-license-name="CC BY-SA 2.5"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1745488" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/1745488/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title='2009-11-16 23:15:03Z' class='relativetime'>Nov 16, 2009 at 23:15</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1745488" href="/posts/1745488/revisions" title="show revision history for this post">
        GONeale
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">1</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1745488" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="1745488" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-112135990" class="comment js-comment " data-comment-id="112135990" data-comment-owner-id="63550" data-comment-score="0">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">CodePlex closed down (but this one is in the CodePlex archive). Perhaps update?</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/63550/peter-mortensen"
                            title="30,620 reputation"
                            class="comment-user">Peter Mortensen</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2020-08-14 15:47:34Z, License: CC BY-SA 4.0' class='relativetime-clean'>Aug 14, 2020 at 15:47</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1745488" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1732382"></a>
<div id="answer-1732382" class="answer js-answer" data-answerid="1732382" data-parentid="1732348" data-score="141" data-position-on-page="15" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1732382">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="141">
            141
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1732382"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1732382"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1732382/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>You want the first <code>&gt;</code> not preceded by a <code>/</code>.  Look <a href="http://www.regular-expressions.info/lookaround.html" rel="noreferrer">here</a> for details on how to do that.  It's referred to as negative lookbehind.</p>

<p>However, a naïve implementation of that will end up matching <code>&lt;bar/&gt;&lt;/foo&gt;</code> in this example document</p>

<pre><code>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;
</code></pre>

<p>Can you provide a little more information on the problem you're trying to solve?  Are you iterating through tags programatically?</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-13T22:47:17"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1732382">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1732382"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1732382" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1732382/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2012-03-19 15:04:25Z' class='relativetime'>Mar 19, 2012 at 15:04</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1732382" href="/posts/1732382/revisions" title="show revision history for this post">
        2 revs, 2 users 89%<br><a href="/users/85306">Jherico</a>

        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">0</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1732382" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="1732382" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1732382" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1744154"></a>
<div id="answer-1744154" class="answer js-answer" data-answerid="1744154" data-parentid="1732348" data-score="109" data-position-on-page="16" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1744154">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="109">
            109
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1744154"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1744154"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1744154/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>If you need this for PHP:</p>

<p>The <a href="http://www.php.net/manual/en/function.dom-import-simplexml.php" rel="noreferrer">PHP DOM</a> <a href="http://php.net/manual/en/class.domdocument.php" rel="noreferrer">functions</a> won't work properly unless it is properly formatted XML. No matter how much better their use is for the rest of mankind.</p>

<p><a href="http://simplehtmldom.sourceforge.net/" rel="noreferrer">simplehtmldom</a> is good, but I found it a bit buggy, and it is is quite memory heavy [Will crash on large pages.]</p>

<p>I have never used <a href="http://querypath.org/" rel="noreferrer">querypath</a>, so can't comment on its usefulness. </p>

<p>Another one to try is my <a href="http://github.com/siteroller/domparser" rel="noreferrer">DOMParser</a> which is very light on resources and I've been using happily for a while. Simple to learn &amp; powerful.</p>

<p>For Python and Java, similar links were posted.</p>

<p>For the downvoters - I only wrote my class when the XML parsers proved unable to withstand real use. Religious downvoting just prevents useful answers from being posted - keep things within perspective of the question, please.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-16T19:02:48"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1744154">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1744154"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1744154" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1744154/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2012-03-19 15:02:18Z' class='relativetime'>Mar 19, 2012 at 15:02</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1744154" href="/posts/1744154/revisions" title="show revision history for this post">
        4 revs, 2 users 98%<br><a href="/users/87520">SamGoody</a>

        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">0</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1744154" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="1744154" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1744154" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="6817767"></a>
<div id="answer-6817767" class="answer js-answer" data-answerid="6817767" data-parentid="1732348" data-score="99" data-position-on-page="17" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="6817767">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="99">
            99
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-6817767"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="6817767"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/6817767/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>Here's the solution:</p>

<pre><code>&lt;?php
// here's the pattern:
$pattern = '/&lt;(\w+)(\s+(\w+)\s*\=\s*(\'|")(.*?)\\4\s*)*\s*(\/&gt;|&gt;)/';

// a string to parse:
$string = 'Hello, try clicking &lt;a href="#paragraph"&gt;here&lt;/a&gt;
    &lt;br/&gt;and check out.&lt;hr /&gt;
    &lt;h2&gt;title&lt;/h2&gt;
    &lt;a name ="paragraph" rel= "I\'m an anchor"&gt;&lt;/a&gt;
    Fine, &lt;span title=\'highlight the "punch"\'&gt;thanks&lt;span&gt;.
    &lt;div class = "clear"&gt;&lt;/div&gt;
    &lt;br&gt;';

// let's get the occurrences:
preg_match_all($pattern, $string, $matches, PREG_PATTERN_ORDER);

// print the result:
print_r($matches[0]);
?&gt;
</code></pre>

<p>To test it deeply, I entered in the string auto-closing tags like:</p>

<ol>
<li>&lt;hr /&gt;</li>
<li>&lt;br/&gt;</li>
<li>&lt;br&gt;</li>
</ol>

<p>I also entered tags with:</p>

<ol>
<li>one attribute</li>
<li>more than one attribute</li>
<li>attributes which value is bound either into <strong>single quotes</strong> or into <strong>double quotes</strong></li>
<li>attributes containing single quotes when the delimiter is a double quote and vice versa</li>
<li>"unpretty" attributes with a space before the "=" symbol, after it and both before and after it.</li>
</ol>

<p>Should you find something which does not work in the proof of concept above, I am available in analyzing the code to improve my skills.</p>

<p><strong>&lt;EDIT&gt;</strong>
I forgot that the question from the user was to avoid the parsing of self-closing tags.
In this case the pattern is simpler, turning into this:</p>

<pre><code>$pattern = '/&lt;(\w+)(\s+(\w+)\s*\=\s*(\'|")(.*?)\\4\s*)*\s*&gt;/';
</code></pre>

<p>The user @ridgerunner noticed that the pattern does not allow <strong>unquoted attributes</strong> or <strong>attributes with no value</strong>. In this case a fine tuning brings us the following pattern:</p>

<pre><code>$pattern = '/&lt;(\w+)(\s+(\w+)(\s*\=\s*(\'|"|)(.*?)\\5\s*)?)*\s*&gt;/';
</code></pre>

<p><strong>&lt;/EDIT&gt;</strong></p>

<h1>Understanding the pattern</h1>

<p>If someone is interested in learning more about the pattern, I provide some line:</p>

<ol>
<li>the first sub-expression (\w+) matches the tag name</li>
<li>the second sub-expression contains the pattern of an attribute. It is composed by:

<ol>
<li>one or more whitespaces \s+</li>
<li>the name of the attribute (\w+)</li>
<li>zero or more whitespaces \s* (it is possible or not, leaving blanks here)</li>
<li>the "=" symbol</li>
<li>again, zero or more whitespaces</li>
<li>the delimiter of the attribute value, a single or double quote ('|"). In the pattern, the single quote is escaped because it coincides with the PHP string delimiter. This sub-expression is captured with the parentheses so it can be referenced again to parse the closure of the attribute, that's why it is very important.</li>
<li>the value of the attribute, matched by <em>almost</em> anything: (.*?); in this specific syntax, using the <strong>greedy match</strong> (the question mark after the asterisk) the RegExp engine enables a "look-ahead"-like operator, which matches anything but what follows this sub-expression</li>
<li>here comes the fun: the \4 part is a <strong>backreference operator</strong>, which refers to a sub-expression defined before in the pattern, in this case, I am referring to the fourth sub-expression, which is the first attribute delimiter found</li>
<li>zero or more whitespaces \s*</li>
<li>the attribute sub-expression ends here, with the specification of zero or more possible occurrences, given by the asterisk.</li>
</ol></li>
<li>Then, since a tag may end with a whitespace before the "&gt;" symbol, zero or more whitespaces are matched with the \s* subpattern.</li>
<li>The tag to match may end with a simple "&gt;" symbol, or a possible XHTML closure, which makes use of the slash before it: (/>|>). The slash is, of course, escaped since it coincides with the regular expression delimiter.</li>
</ol>

<p>Small tip: to better analyze this code it is necessary looking at the source code generated since I did not provide any HTML special characters escaping.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2011-07-25T14:35:59"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="6817767">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/6817767"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-6817767" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/6817767/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2017-10-18 07:33:46Z' class='relativetime'>Oct 18, 2017 at 7:33</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jul 25, 2011 at 14:35. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-6817767" href="/posts/6817767/revisions" title="show revision history for this post">
        6 revs, 2 users 96%<br><a href="/users/383764">Emanuele Del Grande</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">5</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-6817767" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="6817767" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-8098950" class="comment js-comment " data-comment-id="8098950" data-comment-owner-id="433790" data-comment-score="12">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">12</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Does not match valid tags having attributes with no value, i.e. <code>&lt;option selected&gt;</code>. Also does not match valid tags with unquoted attribute values, i.e. <code>&lt;p id=10&gt;</code>.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/433790/ridgerunner"
                            title="32,991 reputation"
                            class="comment-user">ridgerunner</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-07-25 15:01:59Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 25, 2011 at 15:01</span></span>
                        <span title="this comment was edited 1 time">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-8100663" class="comment js-comment " data-comment-id="8100663" data-comment-owner-id="383764" data-comment-score="1">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">1</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@ridgerunner: Thanks very much for your comment. In that case the pattern must change a bit: $pattern = &#39;/&lt;(\w+)(\s+(\w+)(\s*\=\s*(\&#39;|&quot;|)(.*?)\\5\s*)?)*\s*&gt;/&#39;; I tested it and works in case of non-quoted attributes or attributes with no value.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/383764/yodabar"
                            title="4,561 reputation"
                            class="comment-user">yodabar</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-07-25 16:41:46Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 25, 2011 at 16:41</span></span>
                        <span title="this comment was edited 3 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-28400943" class="comment js-comment " data-comment-id="28400943" data-comment-owner-id="1967396" data-comment-score="0">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">How about a space before the tag name: <code>&lt; a href=&quot;http:&#47;&#47;wtf.org&quot; &gt;</code> I&#39;m pretty sure it is legal, but you don&#39;t match it.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/1967396/floris"
                            title="45,381 reputation"
                            class="comment-user">Floris</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2013-10-05 04:58:49Z, License: CC BY-SA 3.0' class='relativetime-clean'>Oct 5, 2013 at 4:58</span></span>
            </div>
        </div>
    </li>
    <li id="comment-28430952" class="comment js-comment " data-comment-id="28430952" data-comment-owner-id="383764" data-comment-score="7">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">7</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">NO sorry, whitespaces before a tagname are illegal. Beyond being &quot;pretty sure&quot; why don&#39;t you provide some evidences of your objection? Here are mine, <a href="http://www.w3.org/TR/xml11/#sec-starttags" rel="nofollow noreferrer">w3.org/TR/xml11/#sec-starttags</a> referred to XML 1.1, and you can find the same for HTML 4, 5 and XHTML, as a W3C validation would also warn if you make a test. As a lot of other blah-blah-poets around here, I did not still receive any intelligent argumentation, apart some hundred of minus to my answers, to demonstrate where my code fails according to the <i>rules of contract</i> specified in the question. I would only welcome them.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/383764/yodabar"
                            title="4,561 reputation"
                            class="comment-user">yodabar</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2013-10-06 18:03:45Z, License: CC BY-SA 3.0' class='relativetime-clean'>Oct 6, 2013 at 18:03</span></span>
            </div>
        </div>
    </li>
    <li id="comment-111341890" class="comment js-comment " data-comment-id="111341890" data-comment-owner-id="22820" data-comment-score="0">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">XML tags can contain colons, e.g. <code>&lt;namespace:name&gt;</code>, is that not so in HTML?</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/22820/qwertie"
                            title="15,526 reputation"
                            class="comment-user">Qwertie</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2020-07-17 21:54:59Z, License: CC BY-SA 4.0' class='relativetime-clean'>Jul 17, 2020 at 21:54</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-6817767" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1756533"></a>
<div id="answer-1756533" class="answer js-answer" data-answerid="1756533" data-parentid="1732348" data-score="93" data-position-on-page="18" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1756533">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="93">
            93
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1756533"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1756533"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1756533/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>Whenever I need to quickly extract something from an HTML document, I use Tidy to convert it to XML and then use XPath or XSLT to get what I need.
In your case, something like this: </p>

<pre><code>//p/a[@href='foo']
</code></pre>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-18T14:50:26"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1756533">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1756533"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1756533" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/1756533/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2014-04-04 08:11:06Z' class='relativetime'>Apr 4, 2014 at 8:11</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1756533" href="/posts/1756533/revisions" title="show revision history for this post">
        2 revs, 2 users 67%<br><a href="/users/1438393">Amal Murali</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">0</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1756533" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="1756533" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1756533" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1744002"></a>
<div id="answer-1744002" class="answer js-answer" data-answerid="1744002" data-parentid="1732348" data-score="91" data-position-on-page="19" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1744002">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="91">
            91
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1744002"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1744002"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1744002/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>I used a open source tool called <a href="http://htmlparser.sourceforge.net/">HTMLParser</a> before. It's designed to parse HTML in various ways and serves the purpose quite well. It can parse HTML as different treenode and you can easily use its API to get attributes out of the node. Check it out and see if this can help you.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-16T18:34:50"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1744002">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1744002"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
                   data-se-share-sheet-license-name="CC BY-SA 2.5"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1744002" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/1744002/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title='2009-11-16 18:34:50Z' class='relativetime'>Nov 16, 2009 at 18:34</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1744002" href="/posts/1744002/revisions" title="show revision history for this post">
        wen
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount"></span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1744002" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="1744002" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-1744002" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="6653839"></a>
<div id="answer-6653839" class="answer js-answer" data-answerid="6653839" data-parentid="1732348" data-score="87" data-position-on-page="20" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="6653839">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="87">
            87
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-6653839"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="6653839"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/6653839/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>I like to parse HTML with regular expressions. I don't attempt to parse idiot HTML that is deliberately broken. This code is my main parser (Perl edition):</p>
<pre><code>$_ = join &quot;&quot;,&lt;STDIN&gt;; tr/\n\r \t/ /s; s/&lt;/\n&lt;/g; s/&gt;/&gt;\n/g; s/\n ?\n/\n/g;
s/^ ?\n//s; s/ $//s; print
</code></pre>
<p>It's called <em>htmlsplit</em>, splits the HTML into lines, with one tag or chunk of text on each line. The lines can then be processed further with other text tools and scripts, such as <a href="http://en.wikipedia.org/wiki/Grep" rel="nofollow noreferrer">grep</a>, <a href="http://en.wikipedia.org/wiki/Sed" rel="nofollow noreferrer">sed</a>, Perl, etc. I'm not even joking :) Enjoy.</p>
<p>It is simple enough to rejig my slurp-everything-first Perl script into a nice streaming thing, if you wish to process enormous web pages. But it's not really necessary.</p>
<p><a href="http://sam.nipl.net/code/nipl-tools/bin/htmlsplit" rel="nofollow noreferrer">HTML Split</a></p>
<hr/>
<p>Some better regular expressions:</p>
<pre><code>/(&lt;.*?&gt;|[^&lt;]+)\s*/g    # Get tags and text
/(\w+)=&quot;(.*?)&quot;/g       # Get attibutes
</code></pre>
<p>They are good for XML / XHTML.</p>
<p>With minor variations, it can cope with messy HTML... or convert the HTML -&gt; XHTML first.</p>
<hr/>
<p>The best way to write regular expressions is in the <a href="http://en.wikipedia.org/wiki/Lex_%28software%29" rel="nofollow noreferrer">Lex</a> / <a href="http://en.wikipedia.org/wiki/Yacc" rel="nofollow noreferrer">Yacc</a> style, not as opaque one-liners or commented multi-line monstrosities. I didn't do that here, yet; these ones barely need it.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2011-07-11T17:13:17"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="6653839">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/6653839"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-6653839" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/6653839/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2020-10-28 23:11:43Z' class='relativetime'>Oct 28, 2020 at 23:11</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jul 11, 2011 at 17:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-6653839" href="/posts/6653839/revisions" title="show revision history for this post">
        6 revs, 3 users 57%<br><a href="/users/218294">Sam Watkins</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">9</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-6653839" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="6653839" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="4"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-8124904" class="comment js-comment " data-comment-id="8124904" data-comment-owner-id="125389" data-comment-score="54">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">54</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">&quot;I don&#39;t attempt to parse idiot HTML that is deliberately broken.&quot;  How does your code know the difference?</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/125389/kevin-panko"
                            title="8,179 reputation"
                            class="comment-user">Kevin Panko</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-07-26 20:38:07Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 26, 2011 at 20:38</span></span>
            </div>
        </div>
    </li>
    <li id="comment-66191097" class="comment js-comment " data-comment-id="66191097" data-comment-owner-id="904933" data-comment-score="5">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">5</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">(get attributes bug 1) <code>&#47;(\w+)=&quot;(.*?)&quot;&#47;</code> assumes double quotes. It will miss values in single quotes. In html version 4 and earlier unquoted value is allowed, if it is a simple word.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/904933/david-andersson"
                            title="725 reputation"
                            class="comment-user">David Andersson</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-09-11 08:23:51Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 11, 2016 at 8:23</span></span>
            </div>
        </div>
    </li>
    <li id="comment-66191152" class="comment js-comment " data-comment-id="66191152" data-comment-owner-id="904933" data-comment-score="4">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">4</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">(get attributes bug 2) <code>&#47;(\w+)=&quot;(.*?)&quot;&#47;</code> may falsely match text that looks like an attribute within an attribute, e.g. <code>&lt;img title=&quot;Nope down=&#39;up&#39; for aussies&quot; src=&quot;...&quot; &#47;&gt;</code>. If applied globally, it will also match such things in ordinary text or in html comments.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/904933/david-andersson"
                            title="725 reputation"
                            class="comment-user">David Andersson</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-09-11 08:28:54Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 11, 2016 at 8:28</span></span>
            </div>
        </div>
    </li>
    <li id="comment-66191321" class="comment js-comment " data-comment-id="66191321" data-comment-owner-id="904933" data-comment-score="3">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">(get attributes bug 3) <code>&#47;(\w+)=&quot;(.*?)&quot;&#47;</code> Optional whitespace should be allowed around the equal sign.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/904933/david-andersson"
                            title="725 reputation"
                            class="comment-user">David Andersson</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-09-11 08:42:23Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 11, 2016 at 8:42</span></span>
            </div>
        </div>
    </li>
    <li id="comment-66191692" class="comment js-comment " data-comment-id="66191692" data-comment-owner-id="904933" data-comment-score="4">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">4</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">(html split bug 1) <code>s&#47;&gt;&#47;&gt;\n&#47;g</code> Since &quot;&gt;&quot; is allowed in data, this may split text lines and confuse subsequent processing.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/904933/david-andersson"
                            title="725 reputation"
                            class="comment-user">David Andersson</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-09-11 09:09:52Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 11, 2016 at 9:09</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-6653839" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>4</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="2708960"></a>
<div id="answer-2708960" class="answer js-answer" data-answerid="2708960" data-parentid="1732348" data-score="71" data-position-on-page="21" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="2708960">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="71">
            71
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-2708960"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="2708960"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2708960/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>There are some nice regexes for replacing HTML with BBCode <a href="http://www.garyshood.com/htmltobb/source.txt" rel="noreferrer">here</a>. For all you nay-sayers, note that he's not trying to fully parse HTML, just to sanitize it. He can probably afford to kill off tags that his simple "parser" can't understand.</p>

<p>For example:</p>

<pre><code>$store =~ s/http:/http:\/\//gi;
$store =~ s/https:/https:\/\//gi;
$baseurl = $store;

if (!$query-&gt;param("ascii")) {
    $html =~ s/\s\s+/\n/gi;
    $html =~ s/&lt;pre(.*?)&gt;(.*?)&lt;\/pre&gt;/\[code]$2\[\/code]/sgmi;
}

$html =~ s/\n//gi;
$html =~ s/\r\r//gi;
$html =~ s/$baseurl//gi;
$html =~ s/&lt;h[1-7](.*?)&gt;(.*?)&lt;\/h[1-7]&gt;/\n\[b]$2\[\/b]\n/sgmi;
$html =~ s/&lt;p&gt;/\n\n/gi;
$html =~ s/&lt;br(.*?)&gt;/\n/gi;
$html =~ s/&lt;textarea(.*?)&gt;(.*?)&lt;\/textarea&gt;/\[code]$2\[\/code]/sgmi;
$html =~ s/&lt;b&gt;(.*?)&lt;\/b&gt;/\[b]$1\[\/b]/gi;
$html =~ s/&lt;i&gt;(.*?)&lt;\/i&gt;/\[i]$1\[\/i]/gi;
$html =~ s/&lt;u&gt;(.*?)&lt;\/u&gt;/\[u]$1\[\/u]/gi;
$html =~ s/&lt;em&gt;(.*?)&lt;\/em&gt;/\[i]$1\[\/i]/gi;
$html =~ s/&lt;strong&gt;(.*?)&lt;\/strong&gt;/\[b]$1\[\/b]/gi;
$html =~ s/&lt;cite&gt;(.*?)&lt;\/cite&gt;/\[i]$1\[\/i]/gi;
$html =~ s/&lt;font color="(.*?)"&gt;(.*?)&lt;\/font&gt;/\[color=$1]$2\[\/color]/sgmi;
$html =~ s/&lt;font color=(.*?)&gt;(.*?)&lt;\/font&gt;/\[color=$1]$2\[\/color]/sgmi;
$html =~ s/&lt;link(.*?)&gt;//gi;
$html =~ s/&lt;li(.*?)&gt;(.*?)&lt;\/li&gt;/\[\*]$2/gi;
$html =~ s/&lt;ul(.*?)&gt;/\[list]/gi;
$html =~ s/&lt;\/ul&gt;/\[\/list]/gi;
$html =~ s/&lt;div&gt;/\n/gi;
$html =~ s/&lt;\/div&gt;/\n/gi;
$html =~ s/&lt;td(.*?)&gt;/ /gi;
$html =~ s/&lt;tr(.*?)&gt;/\n/gi;

$html =~ s/&lt;img(.*?)src="(.*?)"(.*?)&gt;/\[img]$baseurl\/$2\[\/img]/gi;
$html =~ s/&lt;a(.*?)href="(.*?)"(.*?)&gt;(.*?)&lt;\/a&gt;/\[url=$baseurl\/$2]$4\[\/url]/gi;
$html =~ s/\[url=$baseurl\/http:\/\/(.*?)](.*?)\[\/url]/\[url=http:\/\/$1]$2\[\/url]/gi;
$html =~ s/\[img]$baseurl\/http:\/\/(.*?)\[\/img]/\[img]http:\/\/$1\[\/img]/gi;

$html =~ s/&lt;head&gt;(.*?)&lt;\/head&gt;//sgmi;
$html =~ s/&lt;object&gt;(.*?)&lt;\/object&gt;//sgmi;
$html =~ s/&lt;script(.*?)&gt;(.*?)&lt;\/script&gt;//sgmi;
$html =~ s/&lt;style(.*?)&gt;(.*?)&lt;\/style&gt;//sgmi;
$html =~ s/&lt;title&gt;(.*?)&lt;\/title&gt;//sgmi;
$html =~ s/&lt;!--(.*?)--&gt;/\n/sgmi;

$html =~ s/\/\//\//gi;
$html =~ s/http:\//http:\/\//gi;
$html =~ s/https:\//https:\/\//gi;

$html =~ s/&lt;(?:[^&gt;'"]*|(['"]).*?\1)*&gt;//gsi;
$html =~ s/\r\r//gi;
$html =~ s/\[img]\//\[img]/gi;
$html =~ s/\[url=\//\[url=/gi;
</code></pre>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2010-04-25T16:38:42"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="2708960">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/2708960"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-2708960" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/2708960/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2015-05-19 16:20:44Z' class='relativetime'>May 19, 2015 at 16:20</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Apr 25, 2010 at 16:38. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2708960" href="/posts/2708960/revisions" title="show revision history for this post">
        4 revs, 4 users 88%<br><a href="/users/55075">kenorb</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">1</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-2708960" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="2708960" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-52604067" class="comment js-comment " data-comment-id="52604067" data-comment-owner-id="381285" data-comment-score="20">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">20</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Don&#39;t do this. Please.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/381285/maletor"
                            title="6,902 reputation"
                            class="comment-user">maletor</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2015-09-03 02:12:42Z, License: CC BY-SA 3.0' class='relativetime-clean'>Sep 3, 2015 at 2:12</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-2708960" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="3180176"></a>
<div id="answer-3180176" class="answer js-answer" data-answerid="3180176" data-parentid="1732348" data-score="71" data-position-on-page="22" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="3180176">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="71">
            71
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-3180176"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="3180176"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/3180176/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>About the question of the regular expression methods to parse (x)HTML, the answer to all of the ones who spoke about some limits is: you have not been trained enough to rule the force of this powerful weapon, since <strong>nobody</strong> here spoke about <strong>recursion</strong>.</p>
<p>A regular expression-agnostic colleague notified me this discussion, which is not certainly the first on the web about this old and hot topic.</p>
<p>After reading some posts, the first thing I did was looking for the &quot;?R&quot; string in this thread. The second was to search about &quot;recursion&quot;.</p>
<p>No, holy cow, no match found. Since nobody mentioned the main mechanism a parser is built onto, I was soon aware that nobody got the point.</p>
<p>If an (x)HTML parser needs recursion, a regular expression parser without recursion is not enough for the purpose. It's a simple construct.</p>
<p>The <strong>black art of regular expressions is hard to master</strong>, so maybe there are further possibilities we left out while trying and testing our personal solution to capture the whole web in one hand... Well, I am sure about it :)</p>
<p>Here's the magic pattern:</p>
<pre><code>$pattern = &quot;/&lt;([\w]+)([^&gt;]*?)(([\s]*\/&gt;)|(&gt;((([^&lt;]*?|&lt;\!\-\-.*?\-\-&gt;)|(?R))*)&lt;\/\\1[\s]*&gt;))/s&quot;;
</code></pre>
<p>Just try it. It's written as a PHP string, so the &quot;s&quot; modifier makes classes include newlines.</p>
<p>Here's a <strong>sample note on the PHP manual</strong> I wrote in January: <a href="http://php.net/manual/en/regexp.reference.recursive.php" rel="nofollow noreferrer">Reference</a></p>
<p>(Take care. In that note I wrongly used the &quot;m&quot; modifier; it should be erased, notwithstanding it is discarded by the regular expression engine, since no <code>^</code> or <code>$</code> anchoring was used).</p>
<p>Now, we could speak about the limits of this method from a more informed point of view:</p>
<ol>
<li>according to the specific implementation of the regular expression engine, recursion may have a limit in the <strong>number of nested patterns parsed</strong>, but it depends on the language used</li>
<li>although corrupted, (x)HTML does not drive into severe errors. It is not <em>sanitized</em>.</li>
</ol>
<p>Anyhow, it is only a regular expression pattern, but it discloses the possibility to develop of a lot of powerful implementations.</p>
<p>I wrote this pattern to power the <em>recursive descent parser</em> of a template engine I built in my framework, and performances are really great, both in execution times or in memory usage (nothing to do with other template engines which use the same syntax).</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2010-07-05T14:16:50"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="3180176">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/3180176"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-3180176" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/3180176/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2020-08-14 16:06:12Z' class='relativetime'>Aug 14, 2020 at 16:06</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jul 5, 2010 at 14:16. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-3180176" href="/posts/3180176/revisions" title="show revision history for this post">
        4 revs, 4 users 64%<br><a href="/users/383764">Emanuele Del Grande</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">11</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-3180176" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="3180176" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="6"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-3275117" class="comment js-comment " data-comment-id="3275117" data-comment-owner-id="31582" data-comment-score="40">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">40</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I&#39;ll put this in the &quot;Regex which doesn&#39;t allow greater-than in attributes&quot; bin. Check it against &lt;input value=&quot;is 5 &gt; 3?&quot; /&gt;</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/31582/gareth"
                            title="127,913 reputation"
                            class="comment-user">Gareth</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2010-07-05 16:24:02Z, License: CC BY-SA 2.5' class='relativetime-clean'>Jul 5, 2010 at 16:24</span></span>
            </div>
        </div>
    </li>
    <li id="comment-3275182" class="comment js-comment " data-comment-id="3275182" data-comment-owner-id="72943" data-comment-score="74">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">74</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">If you put something like that in production code, you would likely be shot by the maintainer.  A jury would never convict him.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/72943/aehiilrs"
                            title="1,245 reputation"
                            class="comment-user">aehiilrs</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2010-07-05 16:33:01Z, License: CC BY-SA 2.5' class='relativetime-clean'>Jul 5, 2010 at 16:33</span></span>
            </div>
        </div>
    </li>
    <li id="comment-3284978" class="comment js-comment " data-comment-id="3284978" data-comment-owner-id="52443" data-comment-score="32">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="supernova">32</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">Regular expressions can&#39;t work because by definition they are not recursive. Adding a recursive operator to regular expressions basically makes a CFG only with poorer syntax. Why not use something designed to be recursive in the first place rather than violently insert recursion into something already overflowing with extraneous functionality?</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/52443/welbog"
                            title="58,405 reputation"
                            class="comment-user">Welbog</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2010-07-06 18:38:34Z, License: CC BY-SA 2.5' class='relativetime-clean'>Jul 6, 2010 at 18:38</span></span>
            </div>
        </div>
    </li>
    <li id="comment-3321225" class="comment js-comment " data-comment-id="3321225" data-comment-owner-id="102270" data-comment-score="19">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">19</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">My objection isn&#39;t one of functionality it is one of time invested. The problem with RegEx is that by the time you post the cutsey little one liners it appears that you did something more efficiently (&quot;See one line of code!&quot;). And of course no one mentions the half hour (or 3) that they spent with their cheat-sheet and (hopefully) testing every possible permutation of input. And once you get past all that when the maintainer goes to figure out or validate the code they can&#39;t just look at it and see that it is right. The have to dissect the expression and essentially retest it all over again...</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/102270/oorang"
                            title="6,550 reputation"
                            class="comment-user">Oorang</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2010-07-10 15:11:09Z, License: CC BY-SA 2.5' class='relativetime-clean'>Jul 10, 2010 at 15:11</span></span>
            </div>
        </div>
    </li>
    <li id="comment-3321252" class="comment js-comment " data-comment-id="3321252" data-comment-owner-id="102270" data-comment-score="16">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="hot">16</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">... to know that it is good. And that will happen even with people who are <i>good</i> with regex. And honestly I suspect that overwhelming majority of people won&#39;t know it well. So you take one of the most notorious maintenance nightmares and combine it with recursion which is the <i>other</i> maintenance nightmare and I think to myself what I really need on my project is someone a little less clever. The goal is to write code that bad programmers can maintain without breaking the code base. I know it galls to code to the least common denominator. But hiring excellent talent is hard, and you often...</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/102270/oorang"
                            title="6,550 reputation"
                            class="comment-user">Oorang</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2010-07-10 15:17:22Z, License: CC BY-SA 2.5' class='relativetime-clean'>Jul 10, 2010 at 15:17</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-3180176" data-rep=50 data-anon=true>
                    <a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button"></a>
                <span class="js-link-separator dno">&nbsp;|&nbsp;</span>
            <a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>6</b> more comments</a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="2201251"></a>
<div id="answer-2201251" class="answer js-answer" data-answerid="2201251" data-parentid="1732348" data-score="63" data-position-on-page="23" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="2201251">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="63">
            63
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-2201251"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="2201251"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2201251/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>As many people have already pointed out, HTML is not a regular language which can make it very difficult to parse. My solution to this is to turn it into a regular language using a tidy program and then to use an XML parser to consume the results. There are a lot of good options for this. My program is written using Java with the <a href="http://jtidy.sourceforge.net/" rel="noreferrer">jtidy</a> library to turn the HTML into XML and then Jaxen to xpath into the result.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2010-02-04T16:22:00"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="2201251">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/2201251"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
                   data-se-share-sheet-license-name="CC BY-SA 2.5"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-2201251" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/2201251/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title='2010-02-04 16:22:00Z' class='relativetime'>Feb 4, 2010 at 16:22</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Feb 4, 2010 at 16:22. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2201251" href="/posts/2201251/revisions" title="show revision history for this post">
        Corey Sanders
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">0</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-2201251" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="2201251" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-2201251" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="10535487"></a>
<div id="answer-10535487" class="answer js-answer" data-answerid="10535487" data-parentid="1732348" data-score="63" data-position-on-page="24" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="10535487">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="63">
            63
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-10535487"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="10535487"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/10535487/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<pre><code>&lt;\s*(\w+)[^/&gt;]*&gt;
</code></pre>
<p>The parts explained:</p>
<p><code>&lt;</code>: Starting character</p>
<p><code>\s*</code>: It may have whitespaces before the tag name (ugly, but possible).</p>
<p><code>(\w+)</code>: tags can contain letters and numbers (h1). Well, <code>\w</code> also matches '_', but it does not hurt I guess. If curious, use ([a-zA-Z0-9]+) instead.</p>
<p><code>[^/&gt;]*</code>: Anything except <code>&gt;</code> and <code>/</code> until closing <code>&gt;</code></p>
<p><code>&gt;</code>: Closing <code>&gt;</code></p>
<h3>UNRELATED</h3>
<p>And to the fellows, who underestimate regular expressions, saying they are only as powerful as regular languages:</p>
<p>a<sup>n</sup>ba<sup>n</sup>ba<sup>n</sup> which is not regular and not even context free, can be matched with <code>^(a+)b\1b\1$</code></p>
<p>Backreferencing <a href="http://en.wiktionary.org/wiki/FTW" rel="noreferrer">FTW</a>!</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2012-05-10T13:53:54"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="10535487">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/10535487"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-10535487" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/10535487/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2020-10-28 23:09:21Z' class='relativetime'>Oct 28, 2020 at 23:09</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of May 10, 2012 at 13:53. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-10535487" href="/posts/10535487/revisions" title="show revision history for this post">
        7 revs, 4 users 46%<br><a href="/users/277291">daghan</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">4</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-10535487" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="10535487" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-20494033" class="comment js-comment " data-comment-id="20494033" data-comment-owner-id="873843" data-comment-score="0">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@GlitchMr, that was his point. Modern regular expressions are not technically regular, nor is there any reason for them to be.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/873843/alanaktion"
                            title="1,317 reputation"
                            class="comment-user">alanaktion</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2013-02-02 15:45:29Z, License: CC BY-SA 3.0' class='relativetime-clean'>Feb 2, 2013 at 15:45</span></span>
            </div>
        </div>
    </li>
    <li id="comment-20863430" class="comment js-comment " data-comment-id="20863430" data-comment-owner-id="736054" data-comment-score="5">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">5</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">@alanaktion: The &quot;modern&quot; regular expressions (read: with Perl extensions) cannot match within <code>O(MN)</code> (M being regular expression length, N being text length). Backreferences are one of causes of that. The implementation in awk doesn&#39;t have backreferences and matches everything within <code>O(MN)</code> time.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/736054/konrad-borowski"
                            title="11,055 reputation"
                            class="comment-user">Konrad Borowski</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2013-02-14 16:52:45Z, License: CC BY-SA 3.0' class='relativetime-clean'>Feb 14, 2013 at 16:52</span></span>
            </div>
        </div>
    </li>
    <li id="comment-111341972" class="comment js-comment " data-comment-id="111341972" data-comment-owner-id="22820" data-comment-score="3">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">3</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy"><code>&lt;a href=&quot;foo&quot; title=&quot;5&gt;3&quot;&gt; Oops &lt;&#47;a&gt;</code> (quoting @Gareth - odd how people keep posting answers with this specific deficiency over and over. CDATA is kind of easy to overlook, but this is rather more basic)</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/22820/qwertie"
                            title="15,526 reputation"
                            class="comment-user">Qwertie</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2020-07-17 21:59:38Z, License: CC BY-SA 4.0' class='relativetime-clean'>Jul 17, 2020 at 21:59</span></span>
                        <span title="this comment was edited 2 times">
                            <svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>
                        </span>
            </div>
        </div>
    </li>
    <li id="comment-130848209" class="comment js-comment " data-comment-id="130848209" data-comment-owner-id="4116300" data-comment-score="0">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">This regex will not work if html tag will contains <code>&#47;</code> in between. For example : <code>&lt;a href=&quot;example.com&#47;test&#47;example.html&quot;&gt;</code></span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/4116300/roh%c3%act-j%c3%adndal"
                            title="22,170 reputation"
                            class="comment-user">Roh&#xEC;t J&#xED;ndal</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2022-10-18 11:07:47Z, License: CC BY-SA 4.0' class='relativetime-clean'>Oct 18 at 11:07</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-10535487" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="10844758"></a>
<div id="answer-10844758" class="answer js-answer" data-answerid="10844758" data-parentid="1732348" data-score="56" data-position-on-page="25" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="10844758">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="56">
            56
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-10844758"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="10844758"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/10844758/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>If you're simply trying to find those tags (without ambitions of parsing) try this regular expression:</p>

<pre><code>/&lt;[^/]*?&gt;/g
</code></pre>

<p>I wrote it in 30 seconds, and tested here:
<a href="http://gskinner.com/RegExr/">http://gskinner.com/RegExr/</a></p>

<p>It matches the types of tags you mentioned, while ignoring the types you said you wanted to ignore.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2012-06-01T05:13:26"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="10844758">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/10844758"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-10844758" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/10844758/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2016-05-31 07:23:30Z' class='relativetime'>May 31, 2016 at 7:23</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Jun 1, 2012 at 5:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-10844758" href="/posts/10844758/revisions" title="show revision history for this post">
        6 revs, 2 users 96%<br><a href="/users/217867">Lonnie Best</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">2</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-10844758" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="10844758" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-62509129" class="comment js-comment " data-comment-id="62509129" data-comment-owner-id="20938" data-comment-score="2">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="cool">2</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">FYI, you don&#39;t need to escape angle brackets.  Of course, it does no harm to escape them anyway, but look at the confusion you could have avoided. ;)</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/20938/alan-moore"
                            title="72,379 reputation"
                            class="comment-user">Alan Moore</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-05-29 07:47:04Z, License: CC BY-SA 3.0' class='relativetime-clean'>May 29, 2016 at 7:47</span></span>
            </div>
        </div>
    </li>
    <li id="comment-62568124" class="comment js-comment " data-comment-id="62568124" data-comment-owner-id="217867" data-comment-score="0">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">I sometimes escape unnecessarily when I&#39;m unsure if something is special character or not. I&#39;ve edited the answer; it works the same but more concise.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/217867/lonnie-best"
                            title="8,930 reputation"
                            class="comment-user">Lonnie Best</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2016-05-31 07:23:11Z, License: CC BY-SA 3.0' class='relativetime-clean'>May 31, 2016 at 7:23</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-10844758" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="1738126"></a>
<div id="answer-1738126" class="answer js-answer" data-answerid="1738126" data-parentid="1732348" data-score="54" data-position-on-page="26" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="1738126">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="54">
            54
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-1738126"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="1738126"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/1738126/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>It seems to me you're trying to match tags without a "/" at the end. Try this:</p>

<pre><code>&lt;([a-zA-Z][a-zA-Z0-9]*)[^&gt;]*(?&lt;!/)&gt;
</code></pre>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2009-11-15T17:13:19"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="1738126">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/1738126"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
                   data-se-share-sheet-license-name="CC BY-SA 2.5"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-1738126" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/1738126/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title='2009-11-15 17:13:19Z' class='relativetime'>Nov 15, 2009 at 17:13</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 19, 2009 at 1:13. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-1738126" href="/posts/1738126/revisions" title="show revision history for this post">
        manixrock
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">1</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-1738126" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="1738126" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

                        <li id="comment-6771435" class="comment js-comment " data-comment-id="6771435" data-comment-owner-id="402322" data-comment-score="9">
        <div class="js-comment-actions comment-actions">
            <div class="comment-score js-comment-edit-hide">
                    <span title="number of &#x27;useful comment&#x27; votes received"
                            class="warm">9</span>
            </div>
        </div>
        <div class="comment-text  js-comment-text-and-form">
            <div class="comment-body js-comment-edit-hide">
                
                <span class="comment-copy">This does not work. For the input &#39;&lt;x a=&quot;&lt;b&gt;&quot;/&gt;&lt;y&gt;&#39; the matches are x and y, although x is terminated.</span>
                
              <div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/402322/ceving"
                            title="20,585 reputation"
                            class="comment-user">ceving</a>
                </div>
                <span class="comment-date" dir="ltr"><span title='2011-05-04 16:33:18Z, License: CC BY-SA 3.0' class='relativetime-clean'>May 4, 2011 at 16:33</span></span>
            </div>
        </div>
    </li>

            </ul>
	    </div>

        <div id="comments-link-1738126" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="10791453"></a>
<div id="answer-10791453" class="answer js-answer" data-answerid="10791453" data-parentid="1732348" data-score="53" data-position-on-page="27" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="10791453">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="53">
            53
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-10791453"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="10791453"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/10791453/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>It's true that when programming it's usually best to use dedicated parsers and APIs instead of regular expressions when dealing with HTML, especially if accuracy is paramount (e.g., if your processing might have security implications). However, I don’t ascribe to a dogmatic view that XML-style markup should never be processed with regular expressions. There are cases when regular expressions are a great tool for the job, such as when making one-time edits in a text editor, fixing broken XML files, or dealing with file formats that look like but aren’t quite XML. There are some issues to be aware of, but they're not insurmountable or even necessarily relevant.</p>

<p>A simple regex like <code>&lt;([^&gt;"']|"[^"]*"|'[^']*')*&gt;</code> is usually good enough, in cases such as those I just mentioned. It's a naive solution, all things considered, but it does correctly allow unencoded <code>&gt;</code> symbols in attribute values. If you're looking for, e.g., a <code>table</code> tag, you could adapt it as <code>&lt;/?table\b([^&gt;"']|"[^"]*"|'[^']*')*&gt;</code>.</p>

<p>Just to give a sense of what a more "advanced" HTML regex would look like, the following does a fairly respectable job of emulating real-world browser behavior and the HTML5 parsing algorithm:</p>

<pre><code>&lt;/?([A-Za-z][^\s&gt;/]*)(?:=\s*(?:"[^"]*"|'[^']*'|[^\s&gt;]+)|[^&gt;])*(?:&gt;|$)
</code></pre>

<p>The following matches a fairly strict definition of XML tags (although it doesn't account for the full set of Unicode characters allowed in XML names):</p>

<pre><code>&lt;(?:([_:A-Z][-.:\w]*)(?:\s+[_:A-Z][-.:\w]*\s*=\s*(?:"[^"]*"|'[^']*'))*\s*/?|/([_:A-Z][-.:\w]*)\s*)&gt;
</code></pre>

<p>Granted, these don't account for surrounding context and a few edge cases, but even such things could be dealt with if you really wanted to (e.g., by searching between the matches of another regex).</p>

<p>At the end of the day, use the most appropriate tool for the job, even in the cases when that tool happens to be a regex.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2012-05-28T23:27:06"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="10791453">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/10791453"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 3.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-10791453" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/10791453/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2012-05-29 00:01:51Z' class='relativetime'>May 29, 2012 at 0:01</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of May 28, 2012 at 23:27. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-10791453" href="/posts/10791453/revisions" title="show revision history for this post">
        2 revs<br><a href="/users/1421022">slevithan</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">0</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-10791453" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="10791453" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-10791453" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="2226652"></a>
<div id="answer-2226652" class="answer js-answer" data-answerid="2226652" data-parentid="1732348" data-score="50" data-position-on-page="28" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="2226652">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="50">
            50
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-2226652"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="2226652"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/2226652/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>Although it's not suitable and effective to use regular expressions for that purpose sometimes regular expressions provide quick solutions for simple match problems and in my view it's not that horrbile to use regular expressions for trivial works. </p>

<p>There is a <a href="http://blog.stevenlevithan.com/archives/match-innermost-html-element" rel="noreferrer">definitive blog post</a> about matching innermost HTML elements written by Steven Levithan.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2010-02-09T03:59:27"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="2226652">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/2226652"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f2.5%2f"
                   data-se-share-sheet-license-name="CC BY-SA 2.5"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-2226652" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        answered <a href="/posts/2226652/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })"><span title='2010-02-09 03:59:27Z' class='relativetime'>Feb 9, 2010 at 3:59</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Feb 9, 2010 at 3:59. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-2226652" href="/posts/2226652/revisions" title="show revision history for this post">
        Emre Yazici
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount"></span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-2226652" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="2226652" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-2226652" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="4265601"></a>
<div id="answer-4265601" class="answer js-answer" data-answerid="4265601" data-parentid="1732348" data-score="43" data-position-on-page="29" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="4265601">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="43">
            43
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-4265601"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="4265601"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>

    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/4265601/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>If you only want the tag names, it should be possible to do this via a regular expression.</p>
<pre><code>&lt;([a-zA-Z]+)(?:[^&gt;]*[^/] *)?&gt;
</code></pre>
<p>should do what you need. But I think the solution of &quot;moritz&quot; is already fine. I didn't see it in the beginning.</p>
<p>For all downvoters: In some cases it just makes sense to use a regular expression, because it can be the easiest and quickest solution. I agree that in general you should not parse HTML with regular expressions.</p>
<p>But regular expressions can be a very powerful tool when you have a subset of HTML where you know the format and you just want to extract some values. I did that hundreds of times and almost always achieved what I wanted.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2010-11-24T10:11:39"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="4265601">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/4265601"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-4265601" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/4265601/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2020-08-14 16:00:50Z' class='relativetime'>Aug 14, 2020 at 16:00</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Nov 24, 2010 at 10:11. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-4265601" href="/posts/4265601/revisions" title="show revision history for this post">
        5 revs, 2 users 60%<br><a href="/users/518587">morja</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">0</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-4265601" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="4265601" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-4265601" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

                                        
<a name="5210512"></a>
<div id="answer-5210512" class="answer js-answer" data-answerid="5210512" data-parentid="1732348" data-score="39" data-position-on-page="30" data-highest-scored="0" data-question-has-accepted-highest-score="1"  itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
    <div class="post-layout">
        <div class="votecell post-layout--left">
            <div class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="5210512">
        <button class="js-vote-up-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is useful"
                aria-pressed="false"
                aria-label="Up vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 25h32L18 9 2 25Z"/></svg>
        </button>
        <div class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title"
             itemprop="upvoteCount"
             data-value="39">
            39
        </div>
        <button class="js-vote-down-btn flex--item s-btn s-btn__unset c-pointer "
                data-controller="s-tooltip"
                data-s-tooltip-placement="right"
                title="This answer is not useful"
                aria-pressed="false"
                aria-label="Down vote"
                data-selected-classes="fc-theme-primary"
                data-unselected-classes="">
            <svg aria-hidden="true" class="svg-icon iconArrowDownLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 11h32L18 27 2 11Z"/></svg>
        </button>


        
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
        id="saves-btn-5210512"
        data-controller="s-tooltip"
        data-s-tooltip-placement="right"
        data-s-popover-placement=""
        title="Save this answer."
        aria-pressed="false"
        data-post-id="5210512"
        data-post-type-id="2"
        data-user-privilege-for-post-click="0"
        aria-controls=""
        data-s-popover-auto-show="false"
>
    <svg aria-hidden="true" class="fc-theme-primary-500 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
    <svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26l4-2.66ZM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4-6 4Z"/></svg>
</button>







            <div class="js-accepted-answer-indicator flex--item fc-green-700 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
                <div class="ta-center">
                    <svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8Z"/></svg>
                </div>
            </div>
            
<div class="js-bounty-award-container flex--item pb4">

    <div class="d-flex fd-column gs4 ai-center">

            <div class="js-bounty-award flex--item s-badge s-badge__bounty s-badge__sm as-center"
                 title="This answer has been awarded bounties worth 50 reputation by Cole Tobin" data-controller="s-tooltip" data-s-tooltip-placement="right">
                +50
            </div>

    </div>
</div>


    
        <a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/5210512/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4h3L3 9Zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10V5Z"/></svg></a>

</div>

        </div>

        

<div class="answercell post-layout--right">
    
    <div class="s-prose js-post-body" itemprop="text">
<p>The OP doesn't seem to say what he needs to do with the tags. For example, does he need to extract inner text, or just examine the tags?</p>
<p>I'm firmly in the camp that says a regular expression is not the be-all, end-all text parser. I've written a large amount of text-parsing code including <a href="http://www.blackbeltcoder.com/Articles/strings/parsing-html-tags-in-c" rel="nofollow noreferrer">this code to parse HTML tags</a>.</p>
<p>While it's true I'm not all that great with regular expressions, I consider regular expressions just too rigid and hard to maintain for this sort of parsing.</p>
    </div>
    <div class="mt24">
        <div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
            <time itemprop="dateCreated" datetime="2011-03-06T12:38:47"></time>
            <div class="flex--item mr16" style="flex: 1 1 100px;">
                


<div class="js-post-menu pt2" data-post-id="5210512">
    <div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">

            <div class="flex--item">
                <a href="/a/5210512"
                   rel="nofollow"
                   itemprop="url"
                   class="js-share-link js-gps-track"
                   title="Short permalink to this answer"
                   data-gps-track="post.click({ item: 2, priv: 0, post_type: 2 })"
                   data-controller="se-share-sheet"
                   data-se-share-sheet-title="Share a link to this answer"
                   data-se-share-sheet-subtitle=""
                   data-se-share-sheet-post-type="answer"
                   data-se-share-sheet-social="facebook twitter devto"
                   data-se-share-sheet-location="2"
                   data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f"
                   data-se-share-sheet-license-name="CC BY-SA 4.0"
                   data-s-popover-placement="bottom-start">Share</a>
            </div>



            <div class="flex--item">
                <button type="button"
                        id="btnFollowPost-5210512" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
                        data-gps-track="post.click({ item: 14, priv: 0, post_type: 2 })"
                        data-controller="s-tooltip " data-s-tooltip-placement="bottom"
                        data-s-popover-placement="bottom" aria-controls=""
                        title="Follow this answer to receive notifications">
                    Follow
                </button>
            </div>






    </div>
    <div class="js-menu-popup-container"></div>
</div>
            </div>
            <div class="post-signature flex--item fl0">
<div class="user-info ">
    <div class="user-action-time">
        <a href="/posts/5210512/revisions" title="show all edits to this post"
                         class="js-gps-track"
                         data-gps-track="post.click({ item: 4, priv: 0, post_type: 2 })">edited <span title='2020-08-14 15:59:47Z' class='relativetime'>Aug 14, 2020 at 15:59</span></a>
    </div>
    <div class="user-gravatar32">
        
    </div>
    <div class="user-details">
        
        <div class="-flair">
            
        </div>
    </div>
</div>
            </div>


            <div class="post-signature flex--item fl0">
                <div class="user-info">
    <div class="user-details">
        <span class="community-wiki" title="This post is community owned as of Mar 6, 2011 at 12:38. Votes do not generate reputation, and it can be edited by users with 100 rep">
            community wiki
        </span>
    </div><br>
    <div class="user-details">
        <a id="history-5210512" href="/posts/5210512/revisions" title="show revision history for this post">
        2 revs, 2 users 62%<br><a href="/users/522663">Jonathan Wood</a>
        </a>
    </div>
</div>

            </div>
        </div>
        
    
    </div>
    
</div>




            <span class="d-none" itemprop="commentCount">0</span> 
    <div class="post-layout--right js-post-comments-component">
        <div id="comments-5210512" class="comments js-comments-container bt bc-black-075 mt12  dno" data-post-id="5210512" data-min-length="15">
            <ul class="comments-list js-comments-list"
                    data-remaining-comments-count="0"
                    data-canpost="false"
                    data-cansee="true"
                    data-comments-unavailable="false"
                    data-addlink-disabled="true">

            </ul>
	    </div>

        <div id="comments-link-5210512" 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 &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;."  href="#" role="button">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="" role="button"></a>
        </div>         
    </div>
    </div>
</div>

<div class="s-pagination site1 themed pager-answers">
<div class="s-pagination--item is-selected" aria-current=&quot;page&quot;>1</div>
<a class="s-pagination--item js-pagination-item" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?page=2&tab=scoredesc#tab-top" rel="" title="Go to page 2">2</a>
<a class="s-pagination--item js-pagination-item" href="/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?page=2&tab=scoredesc#tab-top" rel="next" title="Go to page 2"> Next</a></div>

                                    <aside class="s-notice s-notice__info post-notice js-post-notice mb16" role="status">
        <div class="d-flex fd-column fw-nowrap">
            <div class="d-flex fw-nowrap">
                    <div class="flex--item mr8">
                        <svg aria-hidden="true" class="svg-icon iconFire" width="18" height="18" viewBox="0 0 18 18"><path opacity=".6" d="M13.18 9c-.8.33-1.46.6-1.97 1.3A9.21 9.21 0 0 0 10 13.89a10 10 0 0 0 1.32-.8 2.53 2.53 0 0 1-.63 2.91h.78a3 3 0 0 0 1.66-.5 4.15 4.15 0 0 0 1.26-1.61c.4-.96.47-1.7.55-2.73.05-1.24-.1-2.49-.46-3.68a2 2 0 0 1-.4.91 2.1 2.1 0 0 1-.9.62Z" fill="#FF6700"/><path d="M10.4 12.11a7.1 7.1 0 0 1 .78-1.76c.3-.47.81-.8 1.37-1.08 0 0-.05-3.27-1.55-5.27-1.5-2-3.37-2.75-4.95-2.61 0 0 4.19 2.94 1.18 5.67-2.14 1.92-3.64 3.81-3.1 5.94a4.14 4.14 0 0 0 3.1 3 4.05 4.05 0 0 1 1.08-3.89C9.42 10.92 8 9.79 8 9.79c.67.02 1.3.28 1.81.72a2 2 0 0 1 .58 1.6Z" fill="#EF2E2E"/></svg>
                    </div>
                <div class="flex--item wmn0 fl1 lh-lg">
                    <div class="flex--item fl1 lh-lg">
                        <b><a href="/help/privileges/protect-questions">Highly active question</a></b>. Earn 10 reputation (not counting the <a href="https://meta.stackexchange.com/questions/141648/what-is-the-association-bonus-and-how-does-it-work">association bonus</a>) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.
                        
                    </div>
                </div>
            </div>
        </div>
</aside>



                            <h2 class="bottom-notice" data-loc="1">
                                <div>
Not the answer you&#x27;re looking for? Browse other questions tagged <ul class='ml0 list-ls-none js-post-tag-list-wrapper d-inline'><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/html" class="post-tag" title="show questions tagged &#39;html&#39;" aria-label="show questions tagged &#39;html&#39;" rel="tag" aria-labelledby="html-container">html</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/regex" class="post-tag" title="show questions tagged &#39;regex&#39;" aria-label="show questions tagged &#39;regex&#39;" rel="tag" aria-labelledby="regex-container">regex</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/xhtml" class="post-tag" title="show questions tagged &#39;xhtml&#39;" aria-label="show questions tagged &#39;xhtml&#39;" rel="tag" aria-labelledby="xhtml-container">xhtml</a></li></ul> or <a href="/questions/ask">ask your own question</a>.                                </div>
                            </h2>
                </div>
            </div>

                
<div id="sidebar" class="show-votes" role="complementary" aria-label="sidebar">
        

    
<div class="s-sidebarwidget s-sidebarwidget__yellow s-anchors s-anchors__grayscale mb16" data-tracker="cb=1">
    <ul class="d-block p0 m0">
                    <li class="s-sidebarwidget--header s-sidebarwidget__small-bold-text d-flex fc-black-600 d:fc-black-900 bb bbw1">
                        The Overflow Blog
                    </li>
        <li class="s-sidebarwidget--item d-flex px16">
            <div class="flex--item1 fl-shrink0">
<svg aria-hidden="true" class="va-text-top svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>            </div>
            <div class="flex--item wmn0 ow-break-word">
                <a href="https://stackoverflow.blog/2022/11/11/another-hard-week-of-layoffs-in-tech-ep-505/" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;The Overflow Blog&quot;,&quot;https://stackoverflow.blog/2022/11/11/another-hard-week-of-layoffs-in-tech-ep-505/&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 1, position: 0 })">Another hard week in tech (Ep. 505)</a>
            </div>
        </li>
        <li class="s-sidebarwidget--item d-flex px16">
            <div class="flex--item1 fl-shrink0">
<svg aria-hidden="true" class="va-text-top svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0ZM2 10.12l6.37-6.43 1.88 1.88L3.88 12H2v-1.88Z"/></svg>            </div>
            <div class="flex--item wmn0 ow-break-word">
                <a href="https://stackoverflow.blog/2022/11/15/tips-and-tricks-for-succeeding-as-a-developer-emigrating-to-japan-ep-505/" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;The Overflow Blog&quot;,&quot;https://stackoverflow.blog/2022/11/15/tips-and-tricks-for-succeeding-as-a-developer-emigrating-to-japan-ep-505/&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 1, position: 1 })">Tips and tricks for succeeding as a developer emigrating to Japan (Ep. 505)</a>
            </div>
        </li>
                    <li class="s-sidebarwidget--header s-sidebarwidget__small-bold-text d-flex fc-black-600 d:fc-black-900 bb bbw1">
                        Upcoming Events
                    </li>
    <li class="s-sidebarwidget--item d-flex px16">
        <div class="flex--item1 fl-shrink0">
            <div class="favicon favicon-stackoverflow" title="Stack Overflow"></div>
        </div>
        <div class="flex--item wmn0 ow-break-word">
            <a href="https://stackoverflow.com/election" class="fc-danger js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;Upcoming Events&quot;,&quot;https://stackoverflow.com/election&quot;,null,null]"  data-gps-track="communitybulletin.click({ priority: 5, position: 2 })">2022 Community Moderator Election</a>
            <div>ends <span title='2022-11-22 20:00:00Z' class='relativetime'>in 7 days</span></div>
        </div>
    </li>
                    <li class="s-sidebarwidget--header s-sidebarwidget__small-bold-text d-flex fc-black-600 d:fc-black-900 bb bbw1">
                        Featured on Meta
                    </li>
        <li class="s-sidebarwidget--item d-flex px16">
            <div class="flex--item1 fl-shrink0">
<div class="favicon favicon-stackexchangemeta" title="Meta Stack Exchange"></div>            </div>
            <div class="flex--item wmn0 ow-break-word">
                <a href="https://meta.stackexchange.com/questions/383026/mobile-app-infrastructure-being-decommissioned" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackexchange.com/questions/383026/mobile-app-infrastructure-being-decommissioned&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 3, position: 3 })">Mobile app infrastructure being decommissioned</a>
            </div>
        </li>
        <li class="s-sidebarwidget--item d-flex px16">
            <div class="flex--item1 fl-shrink0">
<div class="favicon favicon-stackoverflowmeta" title="Meta Stack Overflow"></div>            </div>
            <div class="flex--item wmn0 ow-break-word">
                <a href="https://meta.stackoverflow.com/questions/420897/staging-ground-workflow-canned-comments" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackoverflow.com/questions/420897/staging-ground-workflow-canned-comments&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 6, position: 4 })">Staging Ground Workflow: Canned Comments</a>
            </div>
        </li>
        <li class="s-sidebarwidget--item d-flex px16">
            <div class="flex--item1 fl-shrink0">
<div class="favicon favicon-stackoverflowmeta" title="Meta Stack Overflow"></div>            </div>
            <div class="flex--item wmn0 ow-break-word">
                <a href="https://meta.stackoverflow.com/questions/421038/the-ask-wizard-2022-has-graduated" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackoverflow.com/questions/421038/the-ask-wizard-2022-has-graduated&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 6, position: 5 })">The Ask Wizard (2022) has graduated</a>
            </div>
        </li>
    </ul>
</div>


<div class="js-zone-container zone-container-sidebar">
    <div id="dfp-tsb" class="everyonelovesstackoverflow everyoneloves__top-sidebar"></div>
		<div class="js-report-ad-button-container " style="width: 300px"></div>
</div>
<div class="js-zone-container zone-container-sidebar">
    <div id="dfp-msb" class="everyonelovesstackoverflow everyoneloves__mid-sidebar"></div>
		<div class="js-report-ad-button-container " style="width: 300px"></div>
</div>
<div id="hireme"></div>        <div class="module sidebar-linked">
	<h4 id="h-linked">Linked</h4>
	<div class="linked" data-tracker="lq=1">
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 4456814, position: 0 })">
				<a href="/q/4456814" title="Question score (upvotes - downvotes)">
					<div class="answer-votes answered-accepted default">31</div>
				</a>
				<a href="/questions/4456814/writing-regular-expression-in-php-to-wrap-img-with-a?noredirect=1" class="question-hyperlink">Writing regular expression in PHP to wrap &lt;img&gt; with &lt;a&gt;</a>
			</div>
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 820926, position: 1 })">
				<a href="/q/820926" title="Question score (upvotes - downvotes)">
					<div class="answer-votes answered-accepted default">10</div>
				</a>
				<a href="/questions/820926/regular-expression-to-remove-links?noredirect=1" class="question-hyperlink">regular expression to remove links</a>
			</div>
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 3604109, position: 2 })">
				<a href="/q/3604109" title="Question score (upvotes - downvotes)">
					<div class="answer-votes  default">8</div>
				</a>
				<a href="/questions/3604109/regexp-for-html?noredirect=1" class="question-hyperlink">Regexp for html</a>
			</div>
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 10867836, position: 3 })">
				<a href="/q/10867836" title="Question score (upvotes - downvotes)">
					<div class="answer-votes answered-accepted default">10</div>
				</a>
				<a href="/questions/10867836/regex-convert-html-to-valid-xml-tag?noredirect=1" class="question-hyperlink">Regex - Convert HTML to valid XML tag</a>
			</div>
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 7532202, position: 4 })">
				<a href="/q/7532202" title="Question score (upvotes - downvotes)">
					<div class="answer-votes  default">0</div>
				</a>
				<a href="/questions/7532202/regular-expression-for-remove-html-links?noredirect=1" class="question-hyperlink">Regular expression for remove html links</a>
			</div>
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 2826549, position: 5 })">
				<a href="/q/2826549" title="Question score (upvotes - downvotes)">
					<div class="answer-votes  default">6</div>
				</a>
				<a href="/questions/2826549/regular-expression-to-remove-div-tags?noredirect=1" class="question-hyperlink">Regular Expression to remove Div tags</a>
			</div>
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 56945112, position: 6 })">
				<a href="/q/56945112" title="Question score (upvotes - downvotes)">
					<div class="answer-votes answered-accepted default">0</div>
				</a>
				<a href="/questions/56945112/how-to-split-html-string-using-javascript?noredirect=1" class="question-hyperlink">How to split html string using JavaScript</a>
			</div>
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 3593124, position: 7 })">
				<a href="/q/3593124" title="Question score (upvotes - downvotes)">
					<div class="answer-votes  default">6</div>
				</a>
				<a href="/questions/3593124/getting-text-from-inside-an-html-tag-within-a-local-file-with-grep?noredirect=1" class="question-hyperlink">Getting text from inside an HTML tag within a local file with grep</a>
			</div>
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 1061365, position: 8 })">
				<a href="/q/1061365" title="Question score (upvotes - downvotes)">
					<div class="answer-votes answered-accepted default">4</div>
				</a>
				<a href="/questions/1061365/building-regular-expression-regex-to-extract-text-of-html-tag?noredirect=1" class="question-hyperlink">Building Regular Expression (RegEx) to extract text of HTML tag</a>
			</div>
            <div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 1732348, target_question_id: 21689172, position: 9 })">
				<a href="/q/21689172" title="Question score (upvotes - downvotes)">
					<div class="answer-votes answered-accepted default">0</div>
				</a>
				<a href="/questions/21689172/why-does-this-regex-not-work-r-logo?noredirect=1" class="question-hyperlink">Why does this regex not work: r&#39;.*logo.*&#39;</a>
			</div>
		    <div class="spacer more ml32 pl16 pt8">
                <a href="/questions/linked/1732348">See more linked questions</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/80357" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes answered-accepted large">640</div>
                        </a>
                        <a href="/questions/80357/how-to-match-all-occurrences-of-a-regular-expression-in-ruby" class="question-hyperlink">How to match all occurrences of a regular expression in Ruby</a>
                    </div>
                    <div class="spacer">
                        <a href="/q/1078127" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes answered-accepted large">155</div>
                        </a>
                        <a href="/questions/1078127/are-nested-span-tags-ok-in-xhtml" class="question-hyperlink">Are nested span tags OK in XHTML?</a>
                    </div>
                    <div class="spacer">
                        <a href="/q/1409162" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes answered-accepted large">434</div>
                        </a>
                        <a href="/questions/1409162/what-regex-will-match-every-character-except-comma-or-semi-colon" class="question-hyperlink">What regex will match every character except comma &#39;,&#39; or semi-colon &#39;;&#39;?</a>
                    </div>
                    <div class="spacer">
                        <a href="/q/1687620" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes answered-accepted large">488</div>
                        </a>
                        <a href="/questions/1687620/regex-match-everything-but-a-specific-pattern" class="question-hyperlink">Regex: match everything but a specific pattern</a>
                    </div>
                    <div class="spacer">
                        <a href="/q/3558119" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes answered-accepted large">745</div>
                        </a>
                        <a href="/questions/3558119/are-non-void-self-closing-tags-valid-in-html5" class="question-hyperlink">Are (non-void) self-closing tags valid in HTML5?</a>
                    </div>
                    <div class="spacer">
                        <a href="/q/3617797" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes large">546</div>
                        </a>
                        <a href="/questions/3617797/regex-to-match-only-letters" class="question-hyperlink">Regex to match only letters</a>
                    </div>
                    <div class="spacer">
                        <a href="/q/5319840" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes answered-accepted large">408</div>
                        </a>
                        <a href="/questions/5319840/greedy-vs-reluctant-vs-possessive-qualifiers" class="question-hyperlink">Greedy vs. Reluctant vs. Possessive Qualifiers</a>
                    </div>
                    <div class="spacer">
                        <a href="/q/6109882" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes answered-accepted large">648</div>
                        </a>
                        <a href="/questions/6109882/regex-match-all-characters-between-two-strings" class="question-hyperlink">Regex Match all characters between two strings</a>
                    </div>
                    <div class="spacer">
                        <a href="/q/6863518" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes answered-accepted large">450</div>
                        </a>
                        <a href="/questions/6863518/regex-match-one-of-two-words" class="question-hyperlink">Regex match one of two words</a>
                    </div>
                    <div class="spacer">
                        <a href="/q/55257291" title="Question score (upvotes - downvotes)">
                            <div class="answer-votes answered-accepted default">0</div>
                        </a>
                        <a href="/questions/55257291/java-regex-match-opening-and-closing-curly-tags" class="question-hyperlink">Java – Regex – match opening and closing curly tags</a>
                    </div>
            </div>
        </div>



    <div id="hot-network-questions" class="module tex2jax_ignore">
    <h4>
        <a href="https://stackexchange.com/questions?tab=hot"
           class="js-gps-track s-link s-link__inherit" 
           data-gps-track="posts_hot_network.click({ item_type:1, location:11 })">
            Hot Network Questions
        </a>
    </h4>
    <ul>
            <li >
                <div class="favicon favicon-ell" title="English Language Learners Stack Exchange"></div><a href="https://ell.stackexchange.com/questions/327311/the-meaning-of-lest-you-step-in-a-thousand-puddles-with-fresh-socks-on" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:481 }); posts_hot_network.click({ item_type:2, location:11 })">
                    The meaning of &quot;lest you step in a thousand puddles with fresh socks on&quot;
                </a>

            </li>
            <li >
                <div class="favicon favicon-math" title="Mathematics Stack Exchange"></div><a href="https://math.stackexchange.com/questions/4576813/if-an-orthogonal-matrix-represents-a-reflection-show-that-it-is-symmetric" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:69 }); posts_hot_network.click({ item_type:2, location:11 })">
                    If an orthogonal matrix represents a reflection, show that it is symmetric.
                </a>

            </li>
            <li >
                <div class="favicon favicon-ai" title="Artificial Intelligence Stack Exchange"></div><a href="https://ai.stackexchange.com/questions/37889/are-softmax-outputs-of-classifiers-true-probabilities" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:658 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Are softmax outputs of classifiers true probabilities?
                </a>

            </li>
            <li >
                <div class="favicon favicon-mathematica" title="Mathematica Stack Exchange"></div><a href="https://mathematica.stackexchange.com/questions/276027/why-do-these-patterns-work-with-matchq-but-dont-work-in-a-function-definition" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:387 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Why do these patterns work with MatchQ, but don&#x27;t work in a function definition?
                </a>

            </li>
            <li >
                <div class="favicon favicon-matheducators" title="Mathematics Educators Stack Exchange"></div><a href="https://matheducators.stackexchange.com/questions/25806/what-do-you-do-in-order-to-drag-out-lectures" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:548 }); posts_hot_network.click({ item_type:2, location:11 })">
                    What do you do in order to drag out lectures?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-travel" title="Travel Stack Exchange"></div><a href="https://travel.stackexchange.com/questions/177470/do-trains-travel-at-lower-speed-to-establish-time-buffer-for-possible-delays" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:273 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Do trains travel at lower speed to establish time buffer for possible delays?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-travel" title="Travel Stack Exchange"></div><a href="https://travel.stackexchange.com/questions/177516/refugee-passport-refugee-travel-document-from-france-to-london" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:273 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Refugee Passport / Refugee Travel Document from France to London
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-philosophy" title="Philosophy Stack Exchange"></div><a href="https://philosophy.stackexchange.com/questions/94749/why-do-we-equate-a-mathematical-object-with-what-denotes-it" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:265 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Why do we equate a mathematical object with what denotes it?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-electronics" title="Electrical Engineering Stack Exchange"></div><a href="https://electronics.stackexchange.com/questions/642509/can-i-connect-a-capacitor-to-a-power-source-directly" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:135 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Can I connect a capacitor to a power source directly?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-aviation" title="Aviation Stack Exchange"></div><a href="https://aviation.stackexchange.com/questions/95898/what-does-zero-for-twenty-mean" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:528 }); posts_hot_network.click({ item_type:2, location:11 })">
                    What does &quot;Zero for twenty&quot; mean?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-law" title="Law Stack Exchange"></div><a href="https://law.stackexchange.com/questions/86258/is-it-legal-for-blizzard-to-completely-shut-down-overwatch-1-in-order-to-replace" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:617 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Is it legal for Blizzard to completely shut down Overwatch 1 in order to replace it with Overwatch 2?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-physics" title="Physics Stack Exchange"></div><a href="https://physics.stackexchange.com/questions/736689/rigorously-prove-the-period-of-small-oscillations-by-directly-integrating" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:151 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Rigorously prove the period of small oscillations by directly integrating
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-ell" title="English Language Learners Stack Exchange"></div><a href="https://ell.stackexchange.com/questions/327369/brown-and-clear-water-of-a-stream" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:481 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Brown and clear water of a stream
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-workplace" title="The Workplace Stack Exchange"></div><a href="https://workplace.stackexchange.com/questions/188552/how-to-convince-workplace-im-innocent" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:423 }); posts_hot_network.click({ item_type:2, location:11 })">
                    How to convince workplace I&#x27;m innocent
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-electronics" title="Electrical Engineering Stack Exchange"></div><a href="https://electronics.stackexchange.com/questions/642493/flip-flop-timing-diagram-problem" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:135 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Flip-flop timing diagram problem
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-movies" title="Movies &amp; TV Stack Exchange"></div><a href="https://movies.stackexchange.com/questions/118997/is-the-portrayal-of-people-of-color-in-enola-holmes-movies-historically-accurate" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:367 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Is the portrayal of people of color in Enola Holmes movies historically accurate?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-physics" title="Physics Stack Exchange"></div><a href="https://physics.stackexchange.com/questions/736496/do-solar-panels-act-as-an-electrical-load-on-the-sun" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:151 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Do solar panels act as an electrical load on the sun?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-philosophy" title="Philosophy Stack Exchange"></div><a href="https://philosophy.stackexchange.com/questions/94706/ethics-what-is-the-principle-which-advocates-for-individual-behaviour-based-upo" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:265 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Ethics: What is the principle which advocates for individual behaviour based upon the consequences of group adoption of that same behaviour?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-stats" title="Cross Validated"></div><a href="https://stats.stackexchange.com/questions/595664/t-test-where-one-sample-has-zero-variance" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:65 }); posts_hot_network.click({ item_type:2, location:11 })">
                    t-test where one sample has zero variance?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-boardgames" title="Board &amp; Card Games Stack Exchange"></div><a href="https://boardgames.stackexchange.com/questions/58155/if-pitiless-pontiff-sacrifices-piru-the-volatile-does-it-get-indestructible" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:147 }); posts_hot_network.click({ item_type:2, location:11 })">
                    If Pitiless Pontiff sacrifices Piru, the Volatile, does it get indestructible?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-english" title="English Language &amp; Usage Stack Exchange"></div><a href="https://english.stackexchange.com/questions/598414/is-the-use-of-boot-in-itll-boot-you-none-to-try-weird-or-strange" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:97 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Is the use of &quot;boot&quot; in &quot;it&#x27;ll boot you none to try&quot; weird or strange?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-stackoverflow" title="Stack Overflow"></div><a href="https://stackoverflow.com/questions/74417624/how-does-clang-generate-non-looping-code-for-sum-of-squares" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:1 }); posts_hot_network.click({ item_type:2, location:11 })">
                    How does clang generate non-looping code for sum of squares?
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-scifi" title="Science Fiction &amp; Fantasy Stack Exchange"></div><a href="https://scifi.stackexchange.com/questions/269464/elemental-novel-where-boy-discovers-he-can-talk-to-the-4-different-elements" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:186 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Elemental Novel where boy discovers he can talk to the 4 different elements
                </a>

            </li>
            <li class="dno js-hidden">
                <div class="favicon favicon-electronics" title="Electrical Engineering Stack Exchange"></div><a href="https://electronics.stackexchange.com/questions/642392/why-would-you-sense-peak-inductor-current-from-high-side-pmos-transistor-than-nm" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:135 }); posts_hot_network.click({ item_type:2, location:11 })">
                    Why would you sense peak inductor current from high side PMOS transistor than NMOS?
                </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 id="feed-link" class="js-feed-link">
        <a href="/feeds/question/1732348" title="Feed of this question and its answers">
            <svg aria-hidden="true" class="fc-orange-400 svg-icon iconRss" width="18" height="18" viewBox="0 0 18 18"><path d="M3 1a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2H3Zm0 1.5c6.9 0 12.5 5.6 12.5 12.5H13C13 9.55 8.45 5 3 5V2.5Zm0 5c4.08 0 7.5 3.41 7.5 7.5H8c0-2.72-2.28-5-5-5V7.5Zm0 5c1.36 0 2.5 1.14 2.5 2.5H3v-2.5Z"/></svg>
            Question feed
        </a>
    </div>
    <aside class="s-modal js-feed-link-modal" tabindex="-1" role="dialog" aria-labelledby="feed-modal-title" aria-describedby="feed-modal-description" aria-hidden="true">
        <div class="s-modal--dialog js-modal-dialog wmx4" role="document"  data-controller="se-draggable">
            <h1 class="s-modal--header fw-bold js-first-tabbable" id="feed-modal-title" data-se-draggable-target="handle" tabindex="0">
                Subscribe to RSS
            </h1>
            <div class="d-flex gs4 gsy fd-column">
                <div class="flex--item">
                    <label class="d-block s-label c-default" for="feed-url">
                        Question feed
                        <p class="s-description mt2" id="feed-modal-description">To subscribe to this RSS feed, copy and paste this URL into your RSS reader.</p>
                    </label>
                </div>
                <div class="d-flex ps-relative">
                    <input class="s-input" type="text" name="feed-url" id="feed-url" readonly="readonly" value="https://stackoverflow.com/feeds/question/1732348" />
                    <svg aria-hidden="true" class="s-input-icon fc-orange-400 svg-icon iconRss" width="18" height="18" viewBox="0 0 18 18"><path d="M3 1a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2H3Zm0 1.5c6.9 0 12.5 5.6 12.5 12.5H13C13 9.55 8.45 5 3 5V2.5Zm0 5c4.08 0 7.5 3.41 7.5 7.5H8c0-2.72-2.28-5-5-5V7.5Zm0 5c1.36 0 2.5 1.14 2.5 2.5H3v-2.5Z"/></svg>
                </div>
            </div>
            <a class="s-modal--close s-btn s-btn__muted js-modal-close js-last-tabbable" href="#" aria-label="Close">
                <svg aria-hidden="true" class="svg-icon iconClearSm" width="14" height="14" viewBox="0 0 14 14"><path d="M12 3.41 10.59 2 7 5.59 3.41 2 2 3.41 5.59 7 2 10.59 3.41 12 7 8.41 10.59 12 12 10.59 8.41 7 12 3.41Z"/></svg>
            </a>
        </div>
    </aside>

</div>

    </div>
<script>StackExchange.ready(function(){$.get('/posts/1732348/ivc/31d0');});</script>
<noscript><div><img src="/posts/1732348/ivc/31d0" class="dno" alt="" width="0" height="0"></div></noscript><div style="display:none" id="js-codeblock-lang">lang-html</div></div>


        </div>
    </div>


        
<script>;(()=>{"use strict";var __webpack_modules__={23:(e,t,s)=>{s.d(t,{Z7:()=>l,eq:()=>n,kG:()=>r});const a=/^\/tags\//.test(location.pathname)||/^\/questions\/tagged\//.test(location.pathname)?"tag-pages":/^\/$/.test(location.pathname)||/^\/home/.test(location.pathname)?"home-page":"question-pages";let i=location.hostname;const o={slots:{lb:[[728,90]],mlb:[[728,90]],smlb:[[728,90]],bmlb:[[728,90]],sb:e=>"dfp-tsb"===e?[[300,250],[300,600]]:[[300,250]],"tag-sponsorship":[[730,135]],"mobile-below-question":[[320,50],[300,250]],msb:[[300,250],[300,600]],"talent-conversion-tracking":[[1,1]],"site-sponsorship":[[230,60]]},ids:{"dfp-tlb":"lb","dfp-mlb":"mlb","dfp-smlb":"smlb","dfp-bmlb":"bmlb","dfp-tsb":"sb","dfp-isb":"sb","dfp-tag":"tag-sponsorship","dfp-msb":"msb","dfp-sspon":"site-sponsorship","dfp-m-aq":"mobile-below-question"},idsToExcludeFromAdReports:["dfp-sspon"]};function r(){return Object.keys(o.ids)}function n(e){return o.idsToExcludeFromAdReports.indexOf(e)<0}function l(e){var t=e.split("_")[0];const s=o.ids[t];let r=o.slots[s];return"function"==typeof r&&(r=r(t)),{path:`/248424177/${i}/${s}/${a}`,sizes:r,zone:s}}},865:(e,t,s)=>{function a(e){return"string"==typeof e?document.getElementById(e):e}function i(e){return!!(e=a(e))&&"none"===getComputedStyle(e).display}function o(e){return!i(e)}function r(e){return!!e}function n(e){return/^\s*$/.test(a(e).innerHTML)}function l(e){const{style:t}=e;t.height=t.maxHeight=t.minHeight="auto",t.display="none"}function d(e){const{style:t}=e;t.height=t.maxHeight=t.minHeight="auto",t.display="none",[].forEach.call(e.children,d)}function c(e){const{style:t}=e;t.height=t.maxHeight=t.minHeight="auto",t.removeProperty("display")}function p(e){const t=document.createElement("script");t.src=e,document.body.appendChild(t)}function g(e){return s=e,(t=[]).push=function(e){return s(),delete this.push,this.push(e)},t;var t,s}function h(e){let t="function"==typeof HTMLTemplateElement;var s=document.createElement(t?"template":"div");return e=e.trim(),s.innerHTML=e,t?s.content.firstChild:s.firstChild}s.d(t,{$Z:()=>c,Bv:()=>h,Gx:()=>p,Nj:()=>a,QZ:()=>g,cf:()=>l,pn:()=>o,wo:()=>d,xb:()=>n,xj:()=>i,yb:()=>r})},763:(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{__webpack_require__.d(__webpack_exports__,{t:()=>AdReports});var _common_helper__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(865),_console__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(276),_ad_units__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(23);class AdReports{constructor(e,t){if(this.googletag=e,this.cam=t,this.allowedFileTypes=["image/png","image/jpg","image/jpeg"],this.ignoreValidation=!1,this.cam=t,this.callOnButtonClick=e=>this.onButtonClick(e),this.googletag.pubads().addEventListener("slotRenderEnded",e=>this.handleSlotRendered(e)),Array.isArray(t.slotsRenderedEvents))for(var s=0;s<t.slotsRenderedEvents.length;s++)this.handleSlotRendered(t.slotsRenderedEvents[s])}handleSlotRendered(e){if(e&&e.slot&&!e.isEmpty&&(e.creativeId||e.lineItemId||!e.isEmpty)){var t=e.slot.getSlotElementId();if(t){var s=document.getElementById(t);if(s&&(0,_ad_units__WEBPACK_IMPORTED_MODULE_0__.eq)(t)){var a=s?.closest(".js-zone-container")?.querySelector(".js-report-ad-button-container");a.append(this.createButton(e)),a.style.height="24px"}}}}async onButtonClick(e){e.preventDefault();let t=e.target;const s=t.dataset.modalUrl,a=t.dataset.googleEventData;return await this.loadModal(s,t,a),!1}createButton(e){let t=document.createElement("button");var s=JSON.stringify(e);return t.dataset.googleEventData=s,t.dataset.modalUrl=this.cam.opt.adReportUrl,t.dataset.adUnit=e.slot.getSlotElementId(),t.classList.add("js-report-ad","s-btn","s-btn__link","fs-fine","mt2","float-right"),t.append(document.createTextNode(this.cam.opt.adReportText)),t.removeEventListener("click",this.callOnButtonClick),t.addEventListener("click",this.callOnButtonClick),t}async loadModal(url,$link,googleEventData){try{await window.StackExchange.helpers.loadModal(url,{returnElements:window.$($link)}),this.initForm(googleEventData)}catch(e){var message="",response=e.responseText?eval(`(${e.responseText})`):null;message=response&&response.isLoggedOut?this.cam.opt.adReportLoginExpiredMessage:this.cam.opt.adReportLoginErrorMessage,window.StackExchange.helpers.showToast(message,{type:"danger"})}}removeModal(){window.StackExchange.helpers.closePopups(document.querySelectorAll("."+this.cam.opt.adReportModalClass),"dismiss")}initForm(e,t=!1){this.ignoreValidation=t,this.$form=document.querySelector(".js-ad-report-form"),this.$googleEventData=this.$form.querySelector(".js-json-data"),this.$adReportReasons=this.$form.querySelectorAll(".js-ad-report-reason"),this.$adReportReasonOther=this.$form.querySelector(".js-ad-report-reason-other"),this.$fileUploaderInput=this.$form.querySelector(".js-file-uploader-input"),this.$imageUploader=this.$form.querySelector(".js-image-uploader"),this.$clearImageUpload=this.$form.querySelector(".js-clear-image-upload"),this.$imageUploaderText=this.$form.querySelector(".js-image-uploader-text"),this.$imageUploaderPreview=this.$form.querySelector(".js-image-uploader-preview"),this.$fileErrorMessage=this.$form.querySelector(".js-file-error");const s=this.$form.querySelector(".js-drag-drop-enabled"),a=this.$form.querySelector(".js-drag-drop-disabled");this.$googleEventData.value=e,this.$adReportReasons.forEach((e,t)=>e.addEventListener("change",e=>{this.$adReportReasonOther.classList.toggle("d-none","3"!==e.target.value)})),this.$fileUploaderInput.addEventListener("change",()=>{this.validateFileInput()&&this.updateImagePreview(this.$fileUploaderInput.files)}),this.$clearImageUpload.addEventListener("click",e=>{e.preventDefault(),this.clearImageUpload()});try{this.$fileUploaderInput[0].value="",this.$imageUploader.addEventListener("dragenter dragover dragleave drop",this.preventDefaults),this.$imageUploader.addEventListener("dragenter dragover",this.handleDragStart),this.$imageUploader.addEventListener("dragleave drop",this.handleDragEnd),this.$imageUploader.addEventListener("drop",this.handleDrop)}catch(e){s.classList.add("d-none"),a.classList.remove("d-none")}this.$form.removeEventListener("",this.handleDragEnd),this.$form.addEventListener("submit",async e=>(e.preventDefault(),this.submitForm(),!1))}clearImageUpload(){this.$fileUploaderInput.value="",this.$imageUploaderPreview.setAttribute("src",""),this.$imageUploaderPreview.classList.add("d-none"),this.$clearImageUpload.classList.add("d-none"),this.$imageUploaderText.classList.remove("d-none"),this.$imageUploader.classList.add("p16","ba","bas-dashed","bc-black-100")}preventDefaults(e){e.preventDefault(),e.stopPropagation()}handleDragStart(e){this.$imageUploader.classList.remove("bas-dashed"),this.$imageUploader.classList.add("bas-solid","bc-black-100")}handleDragEnd(e){this.$imageUploader.classList.remove("bas-solid","bc-black-100"),this.$imageUploader.classList.add("bas-dashed")}handleDrop(e){var t=e.originalEvent.dataTransfer.files;FileReader&&t&&1===t.length&&(this.$fileUploaderInput.files=t,this.validateFileInput()&&this.updateImagePreview(t))}setError(e){this.$fileErrorMessage.parentElement.classList.toggle("has-error",e)}updateImagePreview(e){this.$imageUploader.classList.remove("p16","ba","bas-dashed","bc-black-100"),this.$clearImageUpload.classList.remove("d-none"),this.$imageUploaderText.classList.add("d-none");var t=new FileReader;t.onload=e=>{null!=e.target&&(this.$imageUploaderPreview.setAttribute("src",e.target.result),this.$imageUploaderPreview.classList.remove("d-none"))},t.readAsDataURL(e[0])}validateFileInput(){if(this.ignoreValidation)return!0;const e=this.cam.opt.adReportFileTypeErrorMessage,t=this.cam.opt.adReportFileSizeErrorMessage;if(null==this.$fileUploaderInput.files)return!1;var s=this.$fileUploaderInput.files[0];return null==s?(this.setError(!0),!1):this.allowedFileTypes.indexOf(s.type)<0?(this.$fileErrorMessage.textContent=e,this.$fileErrorMessage.classList.remove("d-none"),this.setError(!0),!1):s.size>2097152?(this.$fileErrorMessage.textContent=t,this.$fileErrorMessage.classList.remove("d-none"),this.setError(!0),!1):(this.$fileErrorMessage.classList.add("d-none"),this.setError(!1),!0)}async submitForm(){if(!this.validateFileInput())return!1;this.$form.querySelector("[type=submit]").setAttribute("disabled","true");var e=JSON.parse(this.$googleEventData.value||"{}");e.Reason=parseInt(this.$form.querySelector(".js-ad-report-reason:checked").value,10),e.Description=this.$adReportReasonOther.value,this.$googleEventData.value=JSON.stringify(e);var t=new FormData(this.$form);try{const e=await window.fetch(this.$form.getAttribute("action"),{method:this.$form.getAttribute("method"),body:t,cache:"no-cache"}),a=e.headers.get("content-type")||"",i=await e.text();if(!e.ok)throw new Error("response not valid");if(0===a.indexOf("text/html")){var s=(0,_common_helper__WEBPACK_IMPORTED_MODULE_1__.Bv)(i);const e=s?s.querySelector(".js-modal-content"):null;if(_console__WEBPACK_IMPORTED_MODULE_2__.cM("$popupContent"),_console__WEBPACK_IMPORTED_MODULE_2__.cM(e),!e)throw new Error(`Could not find .js-modal-content in response from ${this.$form.getAttribute("action")}`);document.querySelector(".js-modal-content").replaceWith(e)}else window.StackExchange.helpers.showToast(this.cam.opt.adReportThanksText,{type:"success"}),this.removeModal()}catch(e){window.StackExchange.helpers.showToast(this.cam.opt.adReportErrorText,{type:"danger"})}finally{let e=this.$form.querySelector("[type=submit]");e&&e.removeAttribute("disabled")}}}},276:(e,t,s)=>{function a(...e){}s.d(t,{cM:()=>a})}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var s=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](s,s.exports,__webpack_require__),s.exports}__webpack_require__.d=(e,t)=>{for(var s in t)__webpack_require__.o(t,s)&&!__webpack_require__.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var __webpack_exports__={};(()=>{var e=__webpack_require__(276),t=(e=>(e[e.Above=0]="Above",e[e.Below=1]="Below",e))(t||{});const s=Object.assign({},{"lib":"https://cdn.sstatic.net/clc/js/bundles/gam_loader_script/gam_loader_script.bundle.741.6e0a482112e96aa6b370.min.js","style":null,"u":null,"wa":true,"kt":2000,"tto":true,"h":"clc.stackoverflow.com","allowed":"^(((talent\\.)?stackoverflow)|(blog\\.codinghorror)|(.*\\.googlesyndication)|(serverfault|askubuntu)|([^\\.]+\\.stackexchange))\\.com$","wv":true,"al":false,"abd":true,"cpa_liid":[5882654614],"cpa_cid":[138377597667],"dp":false});var a=__webpack_require__(23),i=__webpack_require__(865),o=__webpack_require__(763);window.cam=new class{constructor(){this.gptImported=!1,this.collapsed={},this.clc_options=s,e.cM("constructor"),this.initGpt(),window.StackExchange.ready(()=>this.init())}init(){if(e.cM("init"),void 0===this.opt)throw new Error("opt not set, required by GAM Loader");this.opt.adReportEnabled?googletag.cmd.push(()=>this.adReports=new o.t(googletag,this)):googletag.cmd.push(()=>this.handleSlotRenderedNoAdReport()),e.cM("setup message handler"),window.addEventListener("message",e=>{this.onmessage(e)})}handleSlotRenderedNoAdReport(){if(googletag.pubads().addEventListener("slotRenderEnded",e=>this.applyExtraMarginBottom(e)),Array.isArray(this.slotsRenderedEvents))for(var e=0;e<this.slotsRenderedEvents.length;e++)this.applyExtraMarginBottom(this.slotsRenderedEvents[e])}onmessage(t){let s="omni";if(t.data&&("string"==typeof t.data||t.data instanceof String))if(0===t.data.indexOf("get-omni-")){e.cM("Recevied get-omni message, sending back omni");var a=t.source,o=this.opt.omni,r="string"==typeof o?o:"";a.postMessage([s,r].join("|"),"*")}else if(0===t.data.indexOf("collapse-")){e.cM("Recevied collapse message, collapse ad iframe"),e.cM(t);for(var n=t.source.window,l=document.getElementsByTagName("IFRAME"),d=0;d<l.length;d++){var c=l[d];if(c.contentWindow==n)return void(0,i.wo)(c.parentElement.parentElement.parentElement)}}else if(0===t.data.indexOf("resize|")){e.cM("Recevied resize message, resize ad iframe"),e.cM(t);let s=this._getFrameByEvent(t),a=t.data.split("|"),i=parseFloat(a[1])+.5;e.cM("New iframe height "+i),s.height=i.toString(),s.parentElement.style.height=i.toString()+"px"}}_getFrameByEvent(e){return Array.from(document.getElementsByTagName("iframe")).filter(t=>t.contentWindow===e.source)[0]}classifyZoneIds(e){const t=e.map(i.Nj).filter(i.yb);return{eligible:t.filter(i.xb).filter(i.pn),ineligible:t.filter(i.xj)}}applyExtraMarginBottom(e){if(e&&e.slot&&!e.isEmpty&&(e.creativeId||e.lineItemId||!e.isEmpty)){var t=e.slot.getSlotElementId();if(t){var s=document.getElementById(t);if(s&&(0,a.eq)(t)){var i=s?.closest(".js-zone-container");i.style.marginBottom="24px"}}}}load(s=(0,a.kG)()){const o=this.opt.tlb_position===t.Above?["dfp-mlb","dfp-smlb"]:["dfp-mlb","dfp-smlb","dfp-tlb"];if(!this.isGptReady())return e.cM("Initializing..."),this.initGpt(),void googletag.cmd.push(()=>this.load(s));e.cM("Attempting to load ads into ids: ",s);const{eligible:r,ineligible:n}=this.classifyZoneIds(s);if(this.initDebugPanel(googletag,r.concat(n)),r.forEach(e=>(0,i.cf)(e)),n.forEach(i.wo),0!==r.length){e.cM("Eligible ids:",r),this.opt.abd&&this.appendAdblockDetector();var l=googletag.pubads().getSlots().filter(e=>s.indexOf(e.getSlotElementId())>=0);googletag.destroySlots(l),this.opt.sf&&(googletag.pubads().setForceSafeFrame(!0),googletag.pubads().setSafeFrameConfig({allowOverlayExpansion:!0,allowPushExpansion:!0,sandbox:!0})),e.cM("Targeting consent: Checking..."),void 0!==this.opt.targeting_consent&&(e.cM("Targeting consent: Parameter set"),e.cM("Targeting consent: Consent given? ",this.opt.targeting_consent),googletag.pubads().setRequestNonPersonalizedAds(this.opt.targeting_consent?0:1),this.opt.targeting_consent||googletag.pubads().setPrivacySettings({limitedAds:!0})),this.opt.ll||googletag.pubads().enableSingleRequest(),cam.sreEvent||(googletag.pubads().addEventListener("slotRenderEnded",e=>this.onSlotRendered(e)),cam.sreEvent=!0),this.setTargeting(googletag);var d=r.filter(e=>!this.opt.ll||o.indexOf(e.id)<0),c=r.filter(e=>!!this.opt.ll&&o.indexOf(e.id)>=0);e.cM("Up front ids:",d),e.cM("Lazy loaded ids:",c),d.forEach(t=>{e.cM(`Defining ad for element ${t.id}`),this.defineSlot(t.id,googletag),t.setAttribute("data-dfp-zone","true")}),googletag.enableServices(),d.forEach(t=>{e.cM(`Displaying ad for element ${t.id}`),googletag.cmd.push(()=>googletag.display(t.id))}),this.opt.ll&&(e.cM("Enabling lazy loading for GAM"),googletag.pubads().enableLazyLoad({fetchMarginPercent:0,renderMarginPercent:0}),e.cM("Setting up lazy loaded ad units"),c.forEach(t=>{e.cM(`Lazy loading - Defining Slot ${t.id}`),this.defineSlot(t.id,googletag)}),c.forEach(t=>{e.cM(`Lazy loading - Displaying ad for element ${t.id}`),googletag.cmd.push(()=>googletag.display(t.id))}))}else e.cM("Found no ad ids on page")}setTargeting(t){let s=this.opt.targeting;"SystemDefault"===s.ProductVariant&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?s.ProductVariant="Dark":s.ProductVariant="Light"),Object.keys(s).forEach(a=>{e.cM(`-> targeting - ${a}: ${s[a]}`),t.pubads().setTargeting(a,s[a])})}appendAdblockDetector(){const e=document.createElement("div");e.className="adsbox",e.id="clc-abd",e.style.position="absolute",e.style.pointerEvents="none",e.innerHTML="&nbsp;",document.body.appendChild(e)}onSlotRendered(s){try{const r=s.slot.getSlotElementId();let n=[];r||n.push("id=0");const l=document.getElementById(r);if(r&&!l&&n.push("el=0"),0!==n.length)return void this.stalled(n.join("&"));const{path:d,sizes:c,zone:p}=(0,a.Z7)(r);if(this.collapsed[p]&&s.isEmpty)return e.cM(`No line item for the element #${l.id}... collapsing.`),void(0,i.wo)(l);if(this.slotsRenderedEvents.push(s),s.lineItemId||s.creativeId||!s.isEmpty){e.cM(`Rendered ad for element #${l.id} [line item #${s.lineItemId}]`),e.cM(s);var o=l.parentElement;if(o.classList.contains("js-zone-container")){switch((0,i.cf)(o),r){case"dfp-tlb":this.opt.tlb_position===t.Above?o.classList.add("mb8"):o.classList.add("mt16");break;case"dfp-tag":o.classList.add("mb8");break;case"dfp-msb":o.classList.add("mt16");break;case"dfp-mlb":case"dfp-smlb":case"dfp-bmlb":o.classList.add("my8");break;case"dfp-isb":o.classList.add("mt24");break;case"dfp-m-aq":o.classList.add("my12"),o.classList.add("mx-auto")}(0,i.$Z)(o),(0,i.$Z)(l)}else e.cM(`No ad for element #${l.id}, collapsing`),e.cM(s),(0,i.wo)(l)}}catch(e){this.stalled("e=1")}}stalled(e){(new Image).src=`https://${this.clc_options.h}/stalled.gif?${e}`}defineSlot(t,s){"dfp-isb"===t&&(e.cM("-> targeting - Sidebar: Inline"),s.pubads().setTargeting("Sidebar",["Inline"])),"dfp-tsb"===t&&(e.cM("-> targeting - Sidebar: Right"),s.pubads().setTargeting("Sidebar",["Right"]));const{path:i,sizes:o,zone:r}=(0,a.Z7)(t);e.cM(`Defining slot for ${t}: ${i}, sizes: ${JSON.stringify(o)}`),s.defineSlot(i,o,t).addService(s.pubads())}importGptLibrary(){this.gptImported||(this.gptImported=!0,void 0===this.opt.targeting_consent||this.opt.targeting_consent?(0,i.Gx)("https://securepubads.g.doubleclick.net/tag/js/gpt.js"):(0,i.Gx)("https://pagead2.googlesyndication.com/tag/js/gpt.js"))}isGptReady(){return"undefined"!=typeof googletag&&!!googletag.apiReady}initGpt(){this.isGptReady()||(window.googletag={cmd:(0,i.QZ)(()=>this.importGptLibrary())})}initDebugPanel(t,s){e.cM("initDebugPanel"),e.cM("Not showing debug panel")}}})()})();</script><script type="text/javascript">
    var cam = cam || {};
    if (typeof cam.opt === 'undefined') {
        cam.opt = {};
    }
    var opt = cam.opt;

    opt.omni = 'BIJeWSbjxtoIAAAAAPxuGgACAAAAAgAAAAAAEgAAAHxodG1sfHJlZ2V4fHhodG1sfAAweXZvsjIIxHgu';

    opt.sf = !0;
    opt.hb = !1;
    opt.ll = !0;
    opt.tlb_position = 0;
    opt.targeting_consent = !1;
    opt.performance_consent = !1;

    opt.targeting = {Registered:['false'],'so-tag':['html','regex','xhtml'],'tag-reportable':['html','regex','xhtml'],'tag-non-reportable':['html','regex','xhtml'],NumberOfAnswers:['20-plus']};
    opt.adReportEnabled = !0;
    opt.adReportUrl = '/ads/report-ad';
    opt.adReportText = 'Report this ad';
	opt.adReportFileTypeErrorMessage = 'Please select a PNG or JPG file.';
    opt.adReportFileSizeErrorMessage = 'The file must be under 2 MiB.';
	opt.adReportErrorText = 'Error uploading ad report.';
	opt.adReportThanksText = 'Thanks for your feedback. We’ll review this against our code of conduct and take action if necessary.';
    opt.adReportLoginExpiredMessage = 'Your login session has expired, please login and try again.';
    opt.adReportLoginErrorMessage = 'An error occurred when loading the report form - please try again';
	opt.adReportModalClass = 'js-ad-report';


    opt.targeting.TargetingConsent = ['False_Passive'];

    const urlParams = new URLSearchParams(window.location.search);
    if (urlParams.has('dfptestads')) {
        const dfptestads = urlParams.get('dfptestads');
        opt.targeting.DfpTestAds = dfptestads;
    }

    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    googletag.cmd.push(function () { cam.load(); });
</script>

        
    <footer id="footer" class="site-footer js-footer" role="contentinfo">
        <div class="site-footer--container">
                <div class="site-footer--logo">
                    
                    <a href="https://stackoverflow.com" aria-label="Stack Overflow"><svg aria-hidden="true" class="native svg-icon iconLogoGlyphMd" width="32" height="37" viewBox="0 0 32 37"><path d="M26 33v-9h4v13H0V24h4v9h22Z" fill="#BCBBBB"/><path d="m21.5 0-2.7 2 9.9 13.3 2.7-2L21.5 0ZM26 18.4 13.3 7.8l2.1-2.5 12.7 10.6-2.1 2.5ZM9.1 15.2l15 7 1.4-3-15-7-1.4 3Zm14 10.79.68-2.95-16.1-3.35L7 23l16.1 2.99ZM23 30H7v-3h16v3Z" fill="#F48024"/></svg></a>
                </div>
            <nav class="site-footer--nav">
                    <div class="site-footer--col">
                        <h5 class="-title"><a href="https://stackoverflow.com" class="js-gps-track" data-gps-track="footer.click({ location: 2, link: 15})">Stack Overflow</a></h5>
                        <ul class="-list js-primary-footer-links">
                            <li><a href="/questions" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 16})">Questions</a></li>
                                <li><a href="/help" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 3 })">Help</a></li>
                        </ul>
                    </div>
                    <div class="site-footer--col">
                        <h5 class="-title"><a href="https://stackoverflow.co/" class="js-gps-track" data-gps-track="footer.click({ location: 2, link: 19 })">Products</a></h5>
                        <ul class="-list">
                            <li><a href="https://stackoverflow.co/teams" class="js-gps-track -link" 
                                                 data-ga="[&quot;teams traffic&quot;,&quot;footer - site nav&quot;,&quot;stackoverflow.com/teams&quot;,null,{&quot;dimension4&quot;:&quot;teams&quot;}]"
                                                 data-gps-track="footer.click({ location: 2, link: 29 })">Teams</a></li>
                            <li><a href="https://stackoverflow.co/advertising" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 21 })">Advertising</a></li>
                            <li><a href="https://stackoverflow.co/collectives" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 40 })">Collectives</a></li>
                            <li><a href="https://stackoverflow.co/talent" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 20 })">Talent</a></li>
                        </ul>
                    </div>
                <div class="site-footer--col">
                    <h5 class="-title"><a class="js-gps-track" data-gps-track="footer.click({ location: 2, link: 1 })" href="https://stackoverflow.co/">Company</a></h5>
                    <ul class="-list">
                            <li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 1 })" href="https://stackoverflow.co/">About</a></li>
                        <li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 27 })" href="https://stackoverflow.co/company/press">Press</a></li>
                            <li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 9 })" href="https://stackoverflow.co/company/work-here">Work Here</a></li>
                        <li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 7 })" href="https://stackoverflow.com/legal">Legal</a></li>
                        <li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 8 })" href="https://stackoverflow.com/legal/privacy-policy">Privacy Policy</a></li>
                        <li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 37 })" href="https://stackoverflow.com/legal/terms-of-service">Terms of Service</a></li>
                            <li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 13 })" href="https://stackoverflow.co/company/contact">Contact Us</a></li>
                            <li class="" id="consent-footer-link"><a class="js-gps-track -link js-cookie-settings" data-gps-track="footer.click({ location: 2, link: 38 })" href="#" data-consent-popup-loader="footer">Cookie Settings</a></li>
                        <li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 39 })" href="https://stackoverflow.com/legal/cookie-policy">Cookie Policy</a></li>
                    </ul>
                </div>
                <div class="site-footer--col site-footer--categories-nav">
                    <div>
                        <h5 class="-title"><a href="https://stackexchange.com" data-gps-track="footer.click({ location: 2, link: 30 })">Stack Exchange Network</a></h5>
                        <ul class="-list">
                            <li>
                                <a href="https://stackexchange.com/sites#technology" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
                                    Technology
                                </a>
                            </li>
                            <li>
                                <a href="https://stackexchange.com/sites#culturerecreation" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
                                    Culture &amp; recreation
                                </a>
                            </li>
                            <li>
                                <a href="https://stackexchange.com/sites#lifearts" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
                                    Life &amp; arts
                                </a>
                            </li>
                            <li>
                                <a href="https://stackexchange.com/sites#science" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
                                    Science
                                </a>
                            </li>
                            <li>
                                <a href="https://stackexchange.com/sites#professional" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
                                    Professional
                                </a>
                            </li>
                            <li>
                                <a href="https://stackexchange.com/sites#business" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
                                    Business
                                </a>
                            </li>

                            <li class="mt16 md:mt0">
                                <a href="https://api.stackexchange.com/" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
                                    API
                                </a>
                            </li>

                            <li>
                                <a href="https://data.stackexchange.com/" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
                                    Data
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
            <div class="site-footer--copyright fs-fine md:mt24">
                <ul class="-list -social md:mb8">
                    <li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link:4 })" href="https://stackoverflow.blog?blb=1">Blog</a></li>
                    <li><a href="https://www.facebook.com/officialstackoverflow/" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 31 })">Facebook</a></li>
                    <li><a href="https://twitter.com/stackoverflow" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 32 })">Twitter</a></li>
                    <li><a href="https://linkedin.com/company/stack-overflow" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 33 })">LinkedIn</a></li>
                    <li><a href="https://www.instagram.com/thestackoverflow" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 36 })">Instagram</a></li>
                </ul>

                <p class="md:mb0">
Site design / logo &#169; 2022 Stack Exchange Inc; user contributions licensed under <span class='td-underline'><a href="https://stackoverflow.com/help/licensing">CC BY-SA</a></span>.                    <span id="svnrev">rev&nbsp;2022.11.14.43032</span>
                </p>
            </div>
        </div>

    </footer>


                <!-- Google tag (gtag.js) -->
            <script async src="https://www.googletagmanager.com/gtag/js?id=G-WCZ03SZFCQ"></script>
            <script>
                window.dataLayer = window.dataLayer || [];
                function gtag() { dataLayer.push(arguments); }
            </script>
        <script>
            StackExchange.ready(function() {

                var ga3Settings = {
                    autoLink: ["stackoverflow.blog","info.stackoverflowsolutions.com","stackoverflowsolutions.com"],
                    sendTitles: true,
                    tracker: window.ga,
                    trackingCodes: [
                        'UA-108242619-1'
                    ],
                    checkDimension: 'dimension42'
                                                    };

                var customGA4Dimensions = {};


                var ga4Settings = {
                    tracker: gtag,
                    trackingCodes: [
                        'G-WCZ03SZFCQ'
                    ],
                    consentsToPerformanceCookies: "denied",
                    consentsToTargetingCookies: "denied",
                    eventParameters: customGA4Dimensions,
                    checkForAdBlock: true
                };

                StackExchange.ga.init({ GA3: ga3Settings, GA4: ga4Settings });


                StackExchange.ga.setDimension('dimension2', '|html|regex|xhtml|');


                StackExchange.ga.setDimension('dimension3', 'Questions/Show');


                StackExchange.ga.setDimension('dimension7', "1668500812.1593626347");

                StackExchange.ga.trackPageView();
            });
        </script>

        
                <div class="ff-sans ps-fixed z-nav-fixed ws4 sm:w-auto p32 sm:p16 bg-black-750 fc-white bar-lg b16 l16 r16 js-consent-banner">
                    <svg aria-hidden="true" class="mln4 mb24 sm:d-none svg-spot spotCookieLg" style="color: var(--theme-button-filled-background-color)" width="96" height="96" viewBox="0 0 96 96">
                        <path d="M35 45.5a7.5 7.5 0 11-15 0 7.5 7.5 0 0115 0zM63.5 63a7.5 7.5 0 100-15 7.5 7.5 0 000 15zm-19 19a7.5 7.5 0 100-15 7.5 7.5 0 000 15z" opacity=".2"/>
                        <path d="M56.99 2.53a23.1 23.1 0 0114.66 6.15h.01l.01.02c.57.55.61 1.27.5 1.74v.07a10.95 10.95 0 01-3.07 4.77 9 9 0 01-6.9 2.5 10.34 10.34 0 01-9.72-10.44v-.08a10 10 0 011.03-3.74l.01-.03.02-.02c.28-.5.82-.92 1.52-.95.63-.02 1.27-.02 1.93.01zm12.04 7.83a20.1 20.1 0 00-12.2-4.83l-.92-.03c-.23.6-.38 1.25-.43 1.94a7.34 7.34 0 006.95 7.34 6 6 0 004.64-1.7c.94-.88 1.6-1.9 1.96-2.72zm15.3 8.76a6.84 6.84 0 00-5.09-.24 7.9 7.9 0 00-3.28 2.05 1.8 1.8 0 00-.3 1.95l.02.02v.02a15.16 15.16 0 008.74 7.47c.64.23 1.32.08 1.8-.33a6.63 6.63 0 001.63-1.97l.01-.03.01-.03c1.67-3.5-.12-7.32-3.54-8.91zm-5.5 3.28c.36-.25.82-.5 1.35-.67.92-.3 1.92-.35 2.89.1 2.14 1 2.92 3.14 2.11 4.88-.12.21-.26.41-.43.6l-.26-.1a12.29 12.29 0 01-5.66-4.81zM32 24a2 2 0 11-4 0 2 2 0 014 0zm12 21a2 2 0 11-4 0 2 2 0 014 0zm36 4a2 2 0 11-4 0 2 2 0 014 0zm-7 21a2 2 0 11-4 0 2 2 0 014 0zM59 81a2 2 0 11-4 0 2 2 0 014 0zM22 63a2 2 0 11-4 0 2 2 0 014 0zm27 7a9 9 0 11-18 0 9 9 0 0118 0zm-3 0a6 6 0 10-12 0 6 6 0 0012 0zM33 41a9 9 0 11-18 0 9 9 0 0118 0zm-15 0a6 6 0 1012 0 6 6 0 00-12 0zm50 11a9 9 0 11-18 0 9 9 0 0118 0zm-3 0a6 6 0 10-12 0 6 6 0 0012 0zM44.08 4.24c.31.48.33 1.09.05 1.58a17.46 17.46 0 00-2.36 8.8c0 9.55 7.58 17.24 16.85 17.24 2.97 0 5.75-.78 8.16-2.15a1.5 1.5 0 012.1.66 12.08 12.08 0 0011 6.74 12.4 12.4 0 007.85-2.75 1.5 1.5 0 012.38.74A45.76 45.76 0 0192 48.16c0 24.77-19.67 44.9-44 44.9S4 72.93 4 48.16C4 25.23 20.84 6.28 42.64 3.58a1.5 1.5 0 011.44.66zM40.22 7C21.32 10.71 7 27.7 7 48.16c0 23.17 18.39 41.9 41 41.9s41-18.73 41-41.9c0-3.52-.42-6.93-1.22-10.2a15.5 15.5 0 01-7.9 2.15c-5.5 0-10.36-2.83-12.97-7.1a19.46 19.46 0 01-8.28 1.85c-11 0-19.86-9.1-19.86-20.24 0-2.7.52-5.26 1.45-7.62zM92 91a2 2 0 100-4 2 2 0 000 4zM7 8.5a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zM82.5 90a1.5 1.5 0 100-3 1.5 1.5 0 000 3zm9.5-7.5a1.5 1.5 0 11-3 0 1.5 1.5 0 013 0zM13.5 8a1.5 1.5 0 100-3 1.5 1.5 0 000 3zM80 14.5a1.5 1.5 0 11-3 0 1.5 1.5 0 013 0zM53.5 20a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"/>
                    </svg>
                    <p class="fs-body2 fw-bold mb4">
                        Your privacy
                    </p>
                    <p class="mb16 s-anchors s-anchors__inherit s-anchors__underlined">
                        By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our <a href="https://stackoverflow.com/legal/cookie-policy">Cookie Policy</a>.
                    </p>
                    <div class="d-flex gs8 ai-stretch fd-column sm:fd-row">
                        <button class="flex--item s-btn s-btn__primary js-accept-cookies js-consent-banner-hide">
                            Accept all cookies
                        </button>

                        <button class="flex--item s-btn s-btn__filled js-cookie-settings" data-consent-popup-loader="banner">
                            Customize settings
                        </button>
                    </div>
                </div>
    <div id="onetrust-consent-sdk" class="d-none"></div>
    <div id="onetrust-banner-sdk" data-controller="s-modal"></div>
    <div id="ot-pc-content" class="d-none"></div>
    <div id="onetrust-style" class="d-none">&nbsp;</div>
    <div class="d-none js-consent-banner-version" data-consent-banner-version="baseline"></div>

    
    </body>
    </html>