Note that there are some explanatory texts on larger screens.

plurals
  1. POregular expression in javascript string split, browser compatibility issue
    primarykey
    data
    text
    <p>I've been investigating this issue that only seems to get worse the more I dig deeper.</p> <p>I started innocently enough trying to use this expression to split a string on HTML 'br' tags:</p> <pre><code>T = captions.innerHTML.split(/&lt;br.*?&gt;/g); </code></pre> <p>This works in every browser (FF, Safari, Chrome), except IE7 and IE8 with example input text like this:</p> <pre><code>is invariably subjective. &lt;br /&gt; The less frequently used warnings (Probably/Possibly) &lt;br /&gt; </code></pre> <p>Please note that the example text contains a space before the '/', and precedes a new line.</p> <p>Both of the following will match all HTML tags in every browser:</p> <pre><code>T = captions.innerHTML.split(/&lt;.*?&gt;/g); T = captions.innerHTML.split(/&lt;.+?&gt;/g); </code></pre> <p>However, surprisingly (to me at least), this <em>does not</em> work in FF and Chrome:</p> <pre><code>T = captions.innerHTML.split(/&lt;br.+?&gt;/g); </code></pre> <p>Edit:</p> <p>This (suggested several times in the responses below,) does not work on IE 7 or 8:</p> <pre><code>T = captions.innerHTML.split(/&lt;br[^&gt;]*&gt;/g); </code></pre> <p>(It did work on Chrome and FF.)</p> <p>My question is: does anyone know an expression that works in all current browsers to match the 'br' tags above (but not other HTML tags). And can anyone confirm that the last example above should be a valid match since two characters are present in the example text before the '>'.</p> <p>PS - my doctype is HTML transitional.</p> <p>Edit:</p> <p>I think I have evidence this is specific to the string.split() behavior on IE, and not regex in general. You have to use split() to see this issue. I have also found a test matrix that shows a failure rate of about 30% for split() test cases when I ran it on IE. The same tests passed 100% on FF and Chrome:</p> <p><a href="http://stevenlevithan.com/demo/split.cfm" rel="nofollow noreferrer">http://stevenlevithan.com/demo/split.cfm</a></p> <p>So far, I have still not found a solution for IE, and the library provided by the author of that test matrix did not fix this case.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload