-1

In Python, you can use re.match(pattern,str) to get the matched groups through "()". For example, if I have:

str = "My name is Derek Last Name"
re.match("My name is (.+)",str).group(1)
//output is "Derek Last Name"

Is there a way to achieve the same functionality in Javascript?

Thanks

Derek

derek
  • 9,358
  • 11
  • 53
  • 94
  • 1
    A bit more searching would've probably done it for ya. [How do you access the matched groups in a JavaScript regular expression?](http://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regular-expression) – CollinD Oct 31 '15 at 17:31
  • You are right. I saw it but I thought it was a different question. – derek Oct 31 '15 at 17:43

1 Answers1

0

You may use the match function.

> var str = "My name is Derek Last Name"
undefined
> str.match(/My name is (.+)/)[1]
'Derek Last Name'
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274