Reputation: 1016
I need to replace a string that has a random number in it.
This is the string
[Async Chat Thread - #<randomNumber>/INFO]:
Here is what i have tried. the \d was one of my many attempts.
str.replace(/\[Async Chat Thread - #\d\/INFO\]:/gi, "");
I am very new to regex so if someone could please explain how i go about this or what i may be doing wrong.
Upvotes: 0
Views: 491
Reputation: 816790
\d
only matches a single digit. If you want to match one or more digits, you need to specify repetition. For example +
denotes the occurrence of the previous group one ore more times:
\d+
OTOH, {x, y}
specifies that the previous group has to occur at least x
and at most y
times:
\d{1,3}
Upvotes: 1