Skip to content
Advertisement

Get the part of the string matched by regex

In the case of re.search(), is there a way I can get hold of just the part of input string that matches the regex? i.e. I just want the "heeehe" part and not the stuff that comes before it:

JavaScript

Advertisement

Answer

match.group(0) is the matched string.

Demo:

JavaScript

You can also omit the argument, 0 is the default.

Advertisement