1

I have a ul with a lot of li each with a child, like that:

<ul>
    <li><a href="#">Belts (2)</a></li>
    <li><a href="#">Tenis (92)</a></li>
    <li><a href="#">T-Shirts (368)</a></li>
</ul>

I need to remove the parentheses and the numbers inside, but let the rest, i.e:

<ul>
    <li><a href="#">Belts</a></li>
    <li><a href="#">Tenis</a></li>
    <li><a href="#">T-Shirts</a></li>
</ul>

How to do it with jquery and regular expression? I have no idea! :(

2 Answers 2

3
$("ul li a").html(function(i, html) {
    return html.replace(/\(\d*\)/, "");
});

DEMO: http://jsfiddle.net/JVVvQ/

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

4 Comments

+ for first with demo. Although you were missing the trailing space.
@JasonMcCreary That doesn't make much sense though :)
well it's the requirement.
@JasonMcCreary Well, if serious, the requirement is to remove the parentheses and the numbers inside, but nothing about the space before.
2
$('a').text(function (_, v) {
    return v.replace(/ \(\d+\)$/, '');
});

Here's the fiddle: http://jsfiddle.net/63H2T/

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.