replace(/[?&]quantity=\d+([&]?)/g,"$1quantity=50$2");
try this ^
([?&])
group together or the character '?' , or '&' (one and only one char) as a group named $ 1
\d+
find at least one digit and find the longest consecutive string of digits , if there is> 1 digit
([&]?)
group either an empty string (if at the end) or '&' as a group named $ 2
'?' means zero or one match
grouping a group of matches into () ... () .... (), and then use it as a result as $ 1, $ 2, $ 3 ... you can search and replace, plus many more complex operations.
source share