简体   繁体   中英

Regex and / and " in Scala/Gatling

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!

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' ('\A' through '\Z'),
  • The lowercase letters 'a' through 'z' ('\a' through '\z'),
  • The digits '0' through '9' ('\0' through '\9'),

Thus, you should change your code to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM