2

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">&nbsp;&gt;&nbsp;&nbsp;&gt;&nbsp;Presentation Text   </div>

And I want to get just this text from all this string, every time at the beginning I have

" &nbsp;&gt;&nbsp;&nbsp;&gt;&nbsp;" + 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?

2 Answers 2

1

Since you're using jQuery, you can use $.trim to remove white-spaces from the beginning and end of your string.

Sign up to request clarification or add additional context in comments.

Comments

1
$('.test').html($('.test').html().replace(/&[^;]+;|\s+$/g, ''));

This will remove all the whitespace characters (\n, \t, space etc) from the end of the text.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.