KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
$.trim() uses the following RegExp to trim a string: /^(\s|\u00A0)+|(\s|\u00A0)+$/g As it turns out, this can be pretty ugly, Example: var mystr = ' some test -- more text new test xxx'; mystr = mystr.replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, ""); This code hangs Firefox and Chrome, it just takes like forever. " mystr " contains whitespaces but mostly hex 160(A0) characters. This "problem" does only occur, if there is no prepending whitespace/A0 , but somewhere within the string. I have no clue why this happens. This expression: /^[\n\r\t \xA0]+|[\n\r\t \xA0]$/g just works fine in all tested scenarios. Maybe a better pattern for that? Source: http://code.jquery.com/jquery-1.4.2.js UPDATE It looks like you can't copy&paste this example string, at some points those A0 characters are replaced. Firebug console will also replace the characters on pasting, you have to create your own string in a sepperate html file/editor to test this.
Tags (comma-separated)
Save Edits
Cancel