Reputation: 9661
I want to continue one task because my head has some problem with a regular expression. How can it be done with a regular expression and jQuery?
I have this HTML:
<div class="test"> > > Presentation Text </div>
And I want to get just this text from all this string, every time at the beginning I have
" > >
" + Some text ... these special character are not changing every time at the begin .
One way is:
$('.test').html($('.test').html().replace(/&[^;]+;/g, ''));
It works, but I realized that I have at the end some bad characters and I have to remove "\n\n\n
" as well
My output:
Presentation Text\n\n\n
But I need the clean text without "\n
" or something else, just "Presentation Text
"
What can I do to solve this problem?
Upvotes: 2
Views: 1462
Reputation: 138017
Since you're using jQuery, you can use $.trim
to remove white-spaces from the beginning and end of your string.
Upvotes: 1
Reputation: 59451
$('.test').html($('.test').html().replace(/&[^;]+;|\s+$/g, ''));
This will remove all the whitespace characters (\n
, \t
, space etc) from the end of the text.
Upvotes: 1