简体   繁体   中英

Is there any regex expression to extract two strings at the same time

{"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

User JSON Extractor for this purpose. As per JMeter documentation of JSON Extractor ,

Names of created variables: Semi-colon separated names of variables that will contain the results of JSON-PATH expressions (must match number of JSON-PATH expressions)

JSON Path Expressions: Semi-colon separated JSON-PATH expressions (must match number of variables)

So the JSon Extractor configuration will be as such,

Names of created variables: bearer; access; refresh

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

Default Values: null;null1;null2

I have checked in JMeter 5.1 and found that if there is a mismatch between number of variables, json expressions and default values then it throughs an exception.

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

So, Default Values: null;null1;null2 is configured in JSON Extractor.

在此处输入图片说明 在此处输入图片说明

This can be done using regular expression extractor. At the end, you will be having two variables (see below) which you can use.

${Token_g1}= Bearer

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

在此处输入图片说明

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