-2
  • Sample string: dadasd_37=12abc_dadasd_asdasdasd_asdas_asd

  • My regex: (?:_37=)([^_]+)

  • What i am trying to get: 12abc (anything that starts with 37= and the word ends with _).

However, the full match is still coming as _37=12abc

math2001
  • 4,167
  • 24
  • 35
Pankaj Jaju
  • 5,371
  • 2
  • 25
  • 41
  • "the word ends with _" That's not doing this *at all*. All `([^_]+)` is going is capture anything that isn't a `_` – math2001 Feb 19 '17 at 07:39
  • Not an expert on regex but this pattern is doing what i want ... well very similar to what i want – Pankaj Jaju Feb 19 '17 at 08:21

1 Answers1

3

Capturing group matches are accessed via the SubMatches collection.

<%
Dim regex, matches, match, strSubject, strResult

strSubject = "dadasd_37=12abc_dadasd_asdasdasd_asdas_asd"

set regex = new RegExp
regex.IgnoreCase = True
regex.Pattern = "(?:_37=)([^_]+)"

set matches = regex.Execute(strSubject)

if matches.Count >= 1 then
    set match = matches(0)
    if match.SubMatches.Count >= 1 then
        strResult = match.SubMatches(0)
    else
        strResult = ""
    end If
else
    strResult = ""
end if

response.write "strResult:" & strResult & ""
%>
Kevin Collins
  • 1,453
  • 1
  • 10
  • 16