1

I have a html response and want to save a token (bid_kid) below

<head>
    <meta name="WT.cg_n" content="Loginsider">
    <meta name="DCSext.loginPage" content="Logg inn - Din side">
    <meta content="no" http-equiv="Content-Language">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script type="text/javascript" src="javascript/xmlhttp.js"></script>
    <link rel="stylesheet" type="text/css" href="_public/gjeff/css/gjeff.css"/>
    <script type="text/javascript" src="_public/gjeff/js/gjeff.min.js"></script>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="static/html5shiv.js"></script>
    <script type="text/javascript" src="static/respond.min.js"></script>
    <![endif]-->
    <script language="JavaScript" src="javascript/dummy_bid20_xxx.js" type="text/javascript"></script>
    <meta name="bid_kid" content="17RA18B5YKIU6A89PIZ6ED0ZYRV1KH">
    <meta name="ajaxurl" content="../no/0/ajax/loginpage-bankid">
    <script src="javascript/init_bid_helper_proto.js" type="text/javascript" defer></script>

    <title>Logg inn - here</title>
</head>

However the check I am running is appearing to be malformated in IntelliJ like this (adds two \):

.check(regex("content=\\\"(?<bid_kid>[0-9A-Z]*)\\\"").find.saveAs("token"))

Do I need to "wrap" the regex experssion in some mather to make this work in Gatling/Scala?

The regex works using a regex tester and it is like this:

content=\"(?<bid_kid>[0-9A-Z]*)\"

Thanks!

Magnus Jensen
  • 905
  • 6
  • 36
  • 73
  • I get an error: java.util.regex.PatternSyntaxException: named capturing group is missing trailing '>' near index 15 content="(?[0-9A-Z]*)" – Magnus Jensen Apr 23 '18 at 14:47
  • using what you suggest makes intellij "go orange" on the \ in \". .check(regex("content=\"(?[0-9A-Z]*)\"").find.saveAs("bidkid")) – Magnus Jensen Apr 23 '18 at 14:48
  • You still do not need to escape `"` whatever you are told by IntelliJ, but as per your comment, the only problem is that you should remove `_` from the group name. Change `bid_kid` to `bidkid`, or just replace the named capturing group with a simple numbered one, i.e. `regex("content=\"([0-9A-Z]*)\"")` – Wiktor Stribiżew Apr 23 '18 at 14:50
  • See here: https://stackoverflow.com/questions/3029657/scala-regex-named-capturing-groups/3029730#3029730 – James Whiteley Apr 23 '18 at 15:07

1 Answers1

0

Acc. to the Java regex documentation, the named group syntax does not allow underscores:

A capturing group can also be assigned a "name", a named-capturing group, and then be back-referenced later by the "name". Group names are composed of the following characters. The first character must be a letter.

  • The uppercase letters 'A' through 'Z' ('\u0041' through '\u005a'),
  • The lowercase letters 'a' through 'z' ('\u0061' through '\u007a'),
  • The digits '0' through '9' ('\u0030' through '\u0039'),

Thus, you should change your code to

.check(regex("content=\\\"(?<bidkid>[0-9A-Z]*)\\\"").find.saveAs("token"))
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563