How to construct regex pattern for this?

I want match with this pattern.
name=(*);
where * is a list of characters. The character can be anything. It can even contain line breaks and whitespaces.
however, the capture group is *.
By that I mean, when I paste regex inside the editor, it should select whatever in between name= and ;.
Also, on the sidenote, I think it will be helpful if you can create separate topic for regex. The people who are into pattern matching can easily the topic

If you want to match a certain string based on things around it, the keywords to search are “lookahead” and “lookbehind”.

/name=(.+);/m

Except that it’s going to stop on ;. Saying “it can contain anything” makes it extremely difficult to make it work (what counts as the final ;)

Its doesn’t work when there is a line break. I tested it on regexr(link). For my case, I can probably get around this problem.

But, it is also capturing name= and ; too. I don’t want to want to capture these.
I just want whatever in between name= and ;.

ah sorry, need . to be dotall, missed the s flag

/name=(.+);/ms

No, it isn’t, it’s matching the name= and ;, which is what it’s supposed to be doing, but it’s only capturing the stuff in the brackets. The “one or more of anything” that is matched in the backets is the capturing group, the bit you want, and you access it with $1 in JS

(for some reason sharing the link with “replace” causes an error when I navigate to it, retyping the “replace” field makes it work if this is the case for you)

1 Like