I'm trying to use ustrregexs to extract substrings from a string. With the data below:

Code:
clear
input str90 var1
"capture123 djuiafjkfehifawyigry capture354 wfhiurugrwioghreuw capture24942chfwrgryugeyuors"
"capture123 djuiafjkfehifawyigry capture354 wfhiurugrwioghreuw capture24942chfwrgryugeyuors"
"capture123 djuiafjkfehifawyigry capture354 wfhiurugrwioghreuw capture24942chfwrgryugeyuors"
end
I want to generate a new variable containing capture123 in observation 1, capture354 in observation 2, and capture24942 in observation 3.

I used the code:

Code:
gen var2 = ustrregexs(_n-1) if ustrregexm(var1,"capture([0-9])+")
But that didn't work as expected:

Code:
. list var2

     +------------+
     |       var2 |
     |------------|
  1. | capture123 |
  2. |          3 |
  3. |            |
     +------------+
I know the regular expression is capturing the correct substrings:

Code:
gen var3 = ustrregexra(var1,"capture([0-9])+","")
. list var3

     +------------------------------------------------------------+
     |                                                       var3 |
     |------------------------------------------------------------|
  1. |  djuiafjkfehifawyigry  wfhiurugrwioghreuw chfwrgryugeyuors |
  2. |  djuiafjkfehifawyigry  wfhiurugrwioghreuw chfwrgryugeyuors |
  3. |  djuiafjkfehifawyigry  wfhiurugrwioghreuw chfwrgryugeyuors |
     +------------------------------------------------------------+
But for some reason ustrregexs() only extracts the first appearance.

Am I doing something wrong or misunderstanding how ustrregexs() works? Is there a better way to do this?