Skip to content

Regex Capturing Incorrect Values #6198

Answered by Hueli
pcarey778 asked this question in Q&A
May 15, 2024 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

@pcarey778 Could it be that you forgot the "slicing" in @pacmano1's suggestion and only tested the RegExp expression?

If I understood him correctly, his solution should look something like this:

var a = msg.slice(0,150) + msg.slice(150).replace(/^{7,}/g, 'test');

By the way, non-capturing does not mean reading over. In your expression

message.replace(/(?:.{150})^{7,}/g, 'test')

the non-capturing does not affect the replace at all, because no reference is made to captured groups in the replacement string. To do this, reference would have to be made to the respective captured groups in the replacement string via $-syntax. However, this is not required for this use case.

Does this perhaps he…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@pacmano1
Comment options

@pcarey778
Comment options

@pacmano1
Comment options

@Hueli
Comment options

Answer selected by pacmano1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants