-2

I'd like to remove a specific string from a piece of text using jQuery.

I used to have a piece of software called RegexBuddy to build regular expressions, but otherwise I am incompetent and useless at it.

Fortunately my question is entirely basic, I need to replace the following string, and only the following string, from a piece of text

[ST1]

Note that basically its ST followed by a number which might change, so it could be [ST12] or [ST15], these need to be removed.

Thanks for your help.

2
  • 1
    Replacing a value in a string is basic javascript. It doesn't require jQuery. Commented Feb 21, 2018 at 19:34
  • Possible duplicate of Replace string to match plural or singular Commented Feb 21, 2018 at 20:24

2 Answers 2

2

Using the Metacharacter \d:

The global flag g it's important to match all occurrences.

var str = "Ele[ST1]E[ST1521]le".replace(/\[ST\d+\]/g, '');
console.log(str);

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

Comments

1

ST[0-9]+ will match all instances of ST followed by 1 or more number characters

\[ST[0-9]+\] will remove the brackets as well.

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.