Scala/Gatling 中的正则表达式和/和"
Regex and / and " in Scala/Gatling
我有一个 html 响应并想在下面保存一个令牌 (bid_kid)
<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>
但是我 运行 的支票在 IntelliJ 中似乎是这样的(添加两个 \):
.check(regex("content=\\"(?<bid_kid>[0-9A-Z]*)\\"").find.saveAs("token"))
我是否需要 "wrap" 某些数学中的正则表达式表达式才能在 Gatling/Scala 中工作?
正则表达式使用正则表达式测试器工作,它是这样的:
content=\"(?<bid_kid>[0-9A-Z]*)\"
谢谢!
累积对于 Java regex documentation,命名组语法不允许下划线:
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'),
因此,您应该将代码更改为
.check(regex("content=\\"(?<bidkid>[0-9A-Z]*)\\"").find.saveAs("token"))
我有一个 html 响应并想在下面保存一个令牌 (bid_kid)
<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>
但是我 运行 的支票在 IntelliJ 中似乎是这样的(添加两个 \):
.check(regex("content=\\"(?<bid_kid>[0-9A-Z]*)\\"").find.saveAs("token"))
我是否需要 "wrap" 某些数学中的正则表达式表达式才能在 Gatling/Scala 中工作?
正则表达式使用正则表达式测试器工作,它是这样的:
content=\"(?<bid_kid>[0-9A-Z]*)\"
谢谢!
累积对于 Java regex documentation,命名组语法不允许下划线:
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'),
因此,您应该将代码更改为
.check(regex("content=\\"(?<bidkid>[0-9A-Z]*)\\"").find.saveAs("token"))