Regex match () works in FF / Chrome, but not IE 8

I have the following jQuery call that returns a match in FF / Chrome but returns null in IE 8.

Here is the fiddle if you want to try it for yourself.

And here is the unsolvable, unacceptable, wayward code:

var m = $('#somediv').text().match(/\d+-(\d+)\sof\s(\d+)/);

EDIT: Thanks to Rob W. I narrowed it down a bit; The following works, so it is specifically "out" or "\ sof \ s" that fails. Fork the violin and try a few for yourself :(

var m = $('#somediv').text().match(/\d+\D(\d+)\D+(\d+)/);
+3
source share
3 answers

Rob W, , replace , , , . Rob W , , jQuery text(),   .

  - HTML, replace, ,   .

Unicode (00A0) IE 8 IE 7:

var m = t.replace(/\u00a0/g, ' ').match(/\d+-(\d+)\sof\s(\d+)/);

IE 9 , , , \s. IE , , ,

+3

 . , .text(), replace .

var m = t.replace(/ /g, ' ').match(/\d+-(\d+)\sof\s(\d+)/);

, alert(t), , .

+2

RegExp:

/\d+-(\d+)\xa0of+\xa0(\d+)/

http://jsfiddle.net/gilly3/KNbpN/

, IE8 (\s).

+2
source

Source: https://habr.com/ru/post/1529180/


All Articles