是否有任何正则表达式可同时提取两个字符串

时间:2019-06-18 09:03:41

标签: regex jmeter

{"token_type":"Bearer","expires_in":31622400,"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjZlMzQ5NWEyMjNjYjhmODczNzRiN2UxODA0ODZkNGFkM2M5MTcyZTllMGMyYWVjOGExOTMxMjBjNmRmYTM0NGIxODUyMzEzYThlMTA3ODIzIn0.eyJhdWQiOiI0IiwianRpIjoiNmUzNDk1YTIyM2NiOGY4NzM3NGI3ZTE4MDQ4NmQ0YWQzYzkxNzJlOWUwYzJhZWM4YTE5MzEyMGM2ZGZhMzQ0YjE4NTIzMTNhOGUxMDc4MjMiLCJpYXQiOjE1NjA4NDY2MTYsIm5iZiI6MTU2MDg0NjYxNiwiZXhwIjoxNTkyNDY5MDE2LCJzdWIiOiIzMzAiLCJzY29wZXMiOltdfQ.nT-c58d1aTUy95QITqbCvwqASzO4kMwLvI9Hc28KNIZalojjXzLqBMUsfSRn_0aMN5lCjD4i4zIZUI2NAnOJbopXl2KusZY602ZYZ0V8QmbyTDic6AdAceA1iVioQlQHVGOM9DNvvKwjSQRbKAQ9lK6_DnQIfWRD4yn32Z_55EY6MsDjzUKRJl6xl0lP0S7wMK8-ak5xDOOgLiiFWVF_4BruAFJdxLOLRSo5wP6Ub77aXUU3OeYgi38wX6IkTxRYnMXLH_vCGelnrvPE8izeU6PhC681HCBDvulZdoRwFc_BNj5iLLhyksKYyHYwu4AHluvzsCQVCL5sPkEe8zYI9UNWn72MsygODQm7718cG0e7hK_q2iA2a4dKPY8vSlXBThdOKnmGhR0GdE26XYYyZeRpvxFA_tMFWclYCSDu6NhpxP52IW0wc8LxtokmAV2bhWdvcvtvrrQeTj86UtpocAyc8hK01aqCgPoPmqKTcboJANLm4Y-8wbnIlZaP1fNdE66NTXXzns_u-ipYMKz377ti7DROvJrfCqgf1fcJ16pHcKExvWzRJ-zKrkMVwxkLtQTeb1Sn3xZfOkm_VGcrbfUfqNGr4GgeonSgBxNwpH6OD71QeuIv8kxvjnXmAoxnxSYeXWz7IxZiKyf0edAtXQpb2qX1Tu1HJ9CnlFVNhmI","refresh_token":"def502003de98bcba253c6d22371677a1a1ebc14e33da134e9868cb357ea58d48a109922f5761606bafbfbbed8a11478b07f880f7ea04bb3810a758b5265f59f68e9312be44dcaa322152740388273d9d0366f17be2ab95db688b69481ca55291cbd194f1f868bd0f654ca5fd0e932a7dec86b6a6684dfb425604619fb881d4a3e9e04a77a4d81c1e682594c2c400d6ea6a148e9f17c410f88a4e4f6a0fccf72063d2eacb91844267ef01d60ea098854ee8a73b7920188e160d7d18b5801c3b2eedf971225dbadf4722830cc211b5872ae5c67161b5dfad009030ddcfb7b1d968fec1f9c95c08efef2e8d367704292f2e9a9da2441ed048806995c7b3d81b815aa0ea232391a856bf418944ac5d42e5ff31205eba577843cbe3d6fd38a03f6690a88dd5c69aebcdd2e78cecbf365166764c9ea1223ec445bfeac73965fb9fa270c54d9dd1f4c80620653b0b8c386a4f2878a3a2fbe41e3d7cf80857b14de18e927c167"}

这是我的令牌会话ID,我想提取Bearer,并以正则表达式开头ey.........c167的令牌,以便提取令牌:

Bearer ey...............c167

2 个答案:

答案 0 :(得分:0)

用户JSON提取器用于此目的。 根据{{​​3}}的JMeter文档,

  

已创建变量的名称:用分号分隔的变量名称,这些变量将包含JSON-PATH表达式的结果(必须   匹配JSON-PATH表达式的数量)

     

JSON路径表达式:以分号分隔的JSON-PATH表达式(必须与变量数量匹配)

因此JSon Extractor配置将是这样,

Names of created variables: bearer; access; refresh

JSON Path Expressions:$.token_type; $.access_token; $.refresh_token

Default Values: null;null1;null2

我检查了JMeter 5.1,发现如果变量数,json表达式和默认值之间不匹配,那么它将通过异常。

java.lang.IllegalArgumentException: Mismatch between number of variables, json expressions and default values

因此,Default Values: null;null1;null2是在JSON提取器中配置的。

JSON Extractor enter image description here enter image description here

答案 1 :(得分:0)

这可以使用正则表达式提取器来完成。最后,您将拥有两个可以使用的变量(见下文)。

$ {Token_g1} =不记名

$ {Token_g3} = eyJ0eXAiOiJKV1QiLCJhbGciOiJSU ........

enter image description here