1、背景:正則表達式
同一個正則表達式匹配多個響應結果值,以前都是添加多個正則表達式,一個一個去獲取須要的值,比較麻煩;今天嘗試了一下用一個正則表達式獲取響應中全部須要的值,使用這種方式也可以獲取多個結果中指定的值,完美省事!spa
2、例如:我要獲取以下響應報文中首次出現的兩個值(barnType 和 trainScheduleBarnId 的值)目標是:{"available":0,"barnNo":"01","barnType":"STX1","recommend":0,"spaceStatus":"FULL","trainScheduleBarnId":3271} 調試
3、接口響應的全部結果:code
{"content":{"barns":[{"available":0,"barnNo":"01","barnType":"STX1","recommend":0,"spaceStatus":"FULL","trainScheduleBarnId":3271},{"available":1,"barnNo":"02","barnType":"STX2","recommend":1,"spaceStatus":"EMPTY","trainScheduleBarnId":3272},{"available":0,"barnNo":"03","barnType":"STX3","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3273},{"available":0,"barnNo":"04","barnType":"STX4","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3274},{"available":1,"barnNo":"05","barnType":"STX1","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3275},{"available":1,"barnNo":"06","barnType":"STX2","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3276},{"available":0,"barnNo":"07","barnType":"STX3","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3277},{"available":0,"barnNo":"08","barnType":"STX4","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3278}],"count":3,"endStationId":2101,"endStationName":"石家莊","endTime":1525491060000,"id":414,"startStationId":2401,"startStationName":"太原","startTime":1525059060000,"trainNo":"K707"},"errorCode":null,"errorMsg":null,"status":"OK"}
4、正則表達式的寫法:blog
5、調試的時候添加一個Debug PostProcessor 調試器接口
6、在Debug PostProcessor中能夠查看到獲取的參數結果io
7、引用方式:${testValues_g1} 和 ${testValues_g2} class
8、這裏還有個小技巧:返回響應結果順序都是不變的,想每次獲取不一樣參數的值,怎麼辦?只須要小小的改動便可test
9、匹配數字的含義:sso
* 0 表示隨機
* -1 表示所有
* 1表示第一個
* 2表示第二個
* ......