Ask coding questions

← Back to all posts
Somethin's wrong? Yep
RixTheTyrunt

result = result.replace(/+=/gi, "++") seems to not work in my code. Embed is below this post:

Answered by 19ecal [earned 5 cycles]
View Answer
Voters
RixTheTyrunt
Comments
hotnewtop
19ecal

+ is a quantifier in Regex, you want your regex to be /\+=/gi, which escapes the quantifier. Your JS error (view by inspecting page (Ctrl+Shift+i))

also should help you understand what is wrong with your regex

RixTheTyrunt

Im just getting started with Regex!

RixTheTyrunt

How can I fix it?

19ecal

@RixTheTyrunt you want line 8 to be result = result.replace(/\+=/gi, "++")

19ecal

@RixTheTyrunt Cool, it can be difficult at first but once you get the hang of it it's really useful

RixTheTyrunt

I just want to replace all += from a variable named result to ++