Regular expressions are used in HTTP monitoring to match patterns in response bodies that basic text matching can’t. For example, if we want to confirm that the next SpaceX mission will use a Falcon rocket and will be launched at Cape Canaveral, we could access the SpaceX API (https://api.spacexdata.com/v3/launches/upcoming?limit=1) and use a regular expression to search the JSON response as follows:

rocket_name[":\s]*Falcon(.|\n)*site_name_long[":\s]*Cape\sCanaveral

where:

  • [”:\s]* - matches any number of quotes, colons, or whitespace characters (i.e., what separates the field name from its value).
  • (.|\n)* - matches any number of characters or newlines (i.e., all the text between “Falcon” and “site_long_name”).

The JSON response body being searched is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
[
  {
    "flight_number": 91,
    "mission_name": "CRS-20",
    "mission_id": [
      "EE86F74"
    ],
    "launch_year": "2020",
    "launch_date_unix": 1583556600,
    "launch_date_utc": "2020-03-07T04:50:00.000Z",
    "launch_date_local": "2020-03-06T23:50:00-05:00",
    "is_tentative": false,
    "tentative_max_precision": "hour",
    "tbd": false,
    "launch_window": null,
    "rocket": {
      "rocket_id": "falcon9",
      "rocket_name": "Falcon 9",
      "rocket_type": "FT",
      "first_stage": {
        "cores": [
          {
            "core_serial": "B1059",
            "flight": 2,
            "block": 5,
            "gridfins": true,
            "legs": true,
            "reused": true,
            "land_success": null,
            "landing_intent": true,
            "landing_type": "RTLS",
            "landing_vehicle": "LZ-1"
          }
        ]
      },
      "second_stage": {
        "block": 5,
        "payloads": [
          {
            "payload_id": "CRS-20",
            "norad_id": [],
            "cap_serial": null,
            "reused": true,
            "customers": [
              "NASA (CRS)"
            ],
            "nationality": "United States",
            "manufacturer": "SpaceX",
            "payload_type": "Dragon 1.1",
            "payload_mass_kg": null,
            "payload_mass_lbs": null,
            "orbit": "ISS",
            "orbit_params": {
              "reference_system": "geocentric",
              "regime": "low-earth",
              "longitude": null,
              "semi_major_axis_km": null,
              "eccentricity": null,
              "periapsis_km": null,
              "apoapsis_km": null,
              "inclination_deg": null,
              "period_min": null,
              "lifespan_years": null,
              "epoch": null,
              "mean_motion": null,
              "raan": null,
              "arg_of_pericenter": null,
              "mean_anomaly": null
            },
            "mass_returned_kg": null,
            "mass_returned_lbs": null,
            "flight_time_sec": null,
            "cargo_manifest": null
          }
        ]
      },
      "fairings": null
    },
    "ships": [],
    "telemetry": {
      "flight_club": null
    },
    "launch_site": {
      "site_id": "ccafs_slc_40",
      "site_name": "CCAFS SLC 40",
      "site_name_long": "Cape Canaveral Air Force Station Space Launch Complex 40"
    },
    "launch_success": null,
    "links": {
      "mission_patch": null,
      "mission_patch_small": null,
      "reddit_campaign": "https://www.reddit.com/r/spacex/comments/ezn6n0/crs20_launch_campaign_thread",
      "reddit_launch": null,
      "reddit_recovery": null,
      "reddit_media": null,
      "presskit": null,
      "article_link": null,
      "wikipedia": null,
      "video_link": null,
      "youtube_id": null,
      "flickr_images": []
    },
    "details": null,
    "upcoming": true,
    "static_fire_date_utc": null,
    "static_fire_date_unix": null,
    "timeline": null,
    "crew": null
  }
]

References