locked
Using Groups in regular Expressions RRS feed

  • Question

  • Hi Experts,

    Am using VSTS Ultimate 2013 to extract a response using Regular Expressions.

    My Expression in webtest Looks like,(Context Parameter name: Details)

    "name":"(.*?)","ID":"(.*?)","District":null,"Region":"(.*?)","RegionNum":(.*?),

    How can i replace name, ID, Region in my requests?

    I tried {{Details_g1}}, {{Details_g2}}, {{Details_g3}}.

    Please suggest me how do i replace the groups.



    Friday, June 12, 2015 7:30 PM

Answers

  • Thanks a lot Tina,

    Please find below the link for the idea,

    http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/8442331-using-multiple-groups-for-regular-expression

    • Marked as answer by Tina-Shi Tuesday, June 23, 2015 2:16 PM
    Wednesday, June 17, 2015 1:04 PM

All replies

  • {{Details_g1}}, {{Details_g2}}, {{Details_g3}} didnt work for me
    Friday, June 12, 2015 8:19 PM
  • Hi AbhishekAruru,

    Based on your issue, could you please tell me where you want to replace name, ID, Region in your requests?

    If possible, I suggest you could share me a screen shot for us so that we will further help you support this issue.

    Generally, I know that we could use the 'Extract Regular Expression' Extraction rule. in the web performance test.

    So please you check if you set the Use Groups as True in the 'Extract Regular Expression' Extraction rule for the web performance test request.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 15, 2015 5:56 AM
  • Hi Tina,

    Am already using "Use Groups" as true. Please find below the request (string body) body where am trying to replace.

    Attached is the screenshot that am using for the Extraction rule.

    ****************** Request body*************************

    [{"Planned":"00000000-0000-0000-0000-000000000000","name":"xxx","NameDet":{"name":"xxx","ID":"yyy","District":null,"Region":"zzz","RegionNumber":aaa,}]

    ***************End of request body*******************************************

    I am trying to replace xxx with {{C_R_Details_g1}}, yyy with {{C_R_Details_g2}} , zzz with {{C_R_Details_g3}} and aaa with {{C_R_Details_g4}}

    Am not sure if am following the right syntax to replace a regular Expression in my request.

    Please suggest.

    Monday, June 15, 2015 1:00 PM
  • I believe the "use groups" allows the extraction of one group, its value will be written to the named context parameter. If you want to extract three values then use three extraction rules, or possibly write your own extraction rule and provide three context parameters to receive the values.

    When using the test with the extract shown check the values shown in context parameters tab of the web test results to see what value has been extracted.

    I think there was another question within the last two months in this forum about using this extraction rule. But I am not able to search properly at the moment.

    Regards

    Adrian

    Monday, June 15, 2015 2:36 PM
  • I guess... the only option is to write a custom plugin to meet my requirement.

    The requirement posted by me is pretty straight forward and easy to work with Jmeter and HP Loadrunner.

    Probably VSTS is not compatible with these tools, because not every one are good with writing C# codes :)

    Monday, June 15, 2015 2:39 PM
  • Hi AbhishekAruru,

    Thanks for your reply.

    I did some research about this "use groups" properties for this 'Extract Regular Expression' Extraction rule in web performance test, I think that the Adrian's explanation is right for this "use groups" in web performance test.

    So if possible, please refer the following document try to write a custom plugin Extraction rule in web performance test

    https://msdn.microsoft.com/en-us/library/ms182545%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    http://blogs.msdn.com/b/amolravande/archive/2009/02/27/how-to-create-a-web-test-plug-in-to-extract-and-store-an-array-of-values-using-visual-studio-team-system.aspx

    If you still want to this feature "use groups" properties for this 'Extract Regular Expression' Extraction rule in web performance test, I suggest you could submit a uservoice:

    http://visualstudio.uservoice.com/forums/121579-visual-studio. The Visual Studio product team is listening to user voice there. You can send your idea there and people can vote. If you submit this suggestion, I hope you could post that link here, I will help you vote it.

    Thanks for your understanding.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 17, 2015 3:20 AM
  • Thanks a lot Tina,

    Please find below the link for the idea,

    http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/8442331-using-multiple-groups-for-regular-expression

    • Marked as answer by Tina-Shi Tuesday, June 23, 2015 2:16 PM
    Wednesday, June 17, 2015 1:04 PM
  • Hi AbhishekAruru,

    please suggest if you got some way to extract multiple group values in different variables,

    I can see only first group value getting stored in variable, how to get values for other groups. 

    I am facing situation same like you have mentioned. 

    Wednesday, January 16, 2019 8:12 AM
  • I believe that you are correct in that only the first group is saved by that extraction rule. I suggest creating your own plugin that uses the same regular expression and saves to multiple context parameters. Here is a version (simplified and not re-tested) of a plugin I used for a regex with a repeated group (i.e. using " ( )+ ").

    public class GetMatchesArticles : WebTestRequestPlugin { public override void PostRequest(object sender, PostRequestEventArgs e) { Regex theRegex = new Regex(" ... ( ... )+ ... "); MatchCollection matches = theRegex.Matches(e.Response.BodyString); int index = 0; foreach (Match mmmm in matches) { if (mmmm.Groups.Count > 1 && mmmm.Groups[1].Captures.Count > 0) { Capture cc = mmmm.Groups[1].Captures[0]; e.WebTest.Context["Match" + index] = cc.Value;

    index++; } } } }

    Simple coding changes can support multiple groups (i.e. " ( ) ( ) ") and getting the context parameter name as a plugin property.

    Regards

    Adrian

    Wednesday, January 16, 2019 9:45 AM