diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp
index 86266fbd74a128a99306e59f2156ba5a6ca90462..4c32723f64ad2fcd7590bcb57a8b6f55bc2b5746 100644
--- a/Applications/ApplicationsLib/ProjectData.cpp
+++ b/Applications/ApplicationsLib/ProjectData.cpp
@@ -23,6 +23,7 @@
 #include <range/v3/action/unique.hpp>
 #include <range/v3/algorithm/contains.hpp>
 #include <range/v3/range/conversion.hpp>
+#include <range/v3/view/adjacent_remove_if.hpp>
 #include <set>
 
 #include "BaseLib/Algorithm.h"
@@ -355,6 +356,61 @@ std::vector<GeoLib::NamedRaster> readRasters(
 //    }
 //}
 
+std::vector<int> parseMaterialIdString(
+    std::string const& material_id_string,
+    MeshLib::PropertyVector<int> const* const material_ids)
+{
+    if (material_id_string == "*")
+    {
+        if (material_ids == nullptr)
+        {
+            OGS_FATAL(
+                "MaterialIDs property is not defined in the mesh but it is "
+                "required to parse '*' definition.");
+        }
+
+        std::vector<int> material_ids_of_this_medium =
+            *material_ids |
+            ranges::views::adjacent_remove_if(std::equal_to<>()) |
+            ranges::to_vector;
+        BaseLib::makeVectorUnique(material_ids_of_this_medium);
+        DBUG("Catch all medium definition for material ids {}.",
+             fmt::join(material_ids_of_this_medium, ", "));
+        return material_ids_of_this_medium;
+    }
+
+    // Usual case of ids separated by comma.
+    return BaseLib::splitMaterialIdString(material_id_string);
+}
+
+template <typename T, typename CreateMedium>
+requires std::convertible_to<decltype(std::declval<CreateMedium>()(
+                                 std::declval<int>())),
+                             std::shared_ptr<T>>
+void createMediumForId(int const id,
+                       std::map<int, std::shared_ptr<T>>& _media,
+                       std::vector<int> const& material_ids_of_this_medium,
+                       CreateMedium&& create_medium)
+{
+    if (_media.find(id) != end(_media))
+    {
+        OGS_FATAL(
+            "Multiple media were specified for the same material id "
+            "'{:d}'. Keep in mind, that if no material id is "
+            "specified, it is assumed to be 0 by default.",
+            id);
+    }
+
+    if (id == material_ids_of_this_medium[0])
+    {
+        _media[id] = create_medium(id);
+    }
+    else
+    {
+        _media[id] = _media[material_ids_of_this_medium[0]];
+    }
+}
+
 }  // namespace
 
 ProjectData::ProjectData() = default;
@@ -560,40 +616,27 @@ void ProjectData::parseMedia(
          //! \ogs_file_param{prj__media__medium}
          media_config->getConfigSubtreeList("medium"))
     {
-        auto material_id_string =
+        auto create_medium = [dim = _mesh_vec[0]->getDimension(),
+                              &medium_config, this](int const id)
+        {
+            return MaterialPropertyLib::createMedium(
+                id, _mesh_vec[0]->getDimension(), medium_config, _parameters,
+                _local_coordinate_system ? &*_local_coordinate_system : nullptr,
+                _curves);
+        };
+
+        auto const material_id_string =
             //! \ogs_file_attr{prj__media__medium__id}
             medium_config.getConfigAttribute<std::string>("id", "0");
 
-        auto const material_ids_of_this_medium =
-            BaseLib::splitMaterialIdString(material_id_string);
+        std::vector<int> const material_ids_of_this_medium =
+            parseMaterialIdString(material_id_string,
+                                  materialIDs(*_mesh_vec[0]));
 
         for (auto const& id : material_ids_of_this_medium)
         {
-            if (_media.find(id) != end(_media))
-            {
-                OGS_FATAL(
-                    "Multiple media were specified for the same material id "
-                    "'{:d}'. Keep in mind, that if no material id is "
-                    "specified, it is assumed to be 0 by default.",
-                    id);
-            }
-
-            if (id == material_ids_of_this_medium[0])
-            {
-                _media[id] = MaterialPropertyLib::createMedium(
-                    id, _mesh_vec[0]->getDimension(), medium_config,
-                    _parameters,
-                    _local_coordinate_system ? &*_local_coordinate_system
-                                             : nullptr,
-                    _curves);
-            }
-            else
-            {
-                // This medium has multiple material IDs assigned and this is
-                // not the first material ID. Therefore we can reuse the medium
-                // we created before.
-                _media[id] = _media[material_ids_of_this_medium[0]];
-            }
+            createMediumForId(id, _media, material_ids_of_this_medium,
+                              create_medium);
         }
     }
 
diff --git a/MaterialLib/MPL/MaterialSpatialDistributionMap.cpp b/MaterialLib/MPL/MaterialSpatialDistributionMap.cpp
index 3709e1ad453e2d677778d9716fa843574770ce0a..dcde7ccfa7d5254a4de478ecf0fb6549fc05bf54 100644
--- a/MaterialLib/MPL/MaterialSpatialDistributionMap.cpp
+++ b/MaterialLib/MPL/MaterialSpatialDistributionMap.cpp
@@ -11,6 +11,11 @@
  */
 #include "MaterialSpatialDistributionMap.h"
 
+#include <spdlog/fmt/bundled/core.h>
+#include <spdlog/fmt/bundled/ranges.h>
+
+#include <range/v3/view/map.hpp>
+
 #include "MeshLib/Mesh.h"
 
 namespace MaterialPropertyLib
@@ -28,7 +33,36 @@ Medium const* MaterialSpatialDistributionMap::getMedium(
     auto const material_id =
         material_ids_ == nullptr ? 0 : (*material_ids_)[element_id];
 
-    return media_.at(material_id).get();
+    assert(!media_.empty());
+
+    if (auto const it = media_.find(material_id); it != media_.end())
+    {
+        return it->second.get();
+    }
+
+    //
+    // Error handling until end of the function.
+    //
+
+    if (material_ids_ == nullptr)
+    {
+        assert(material_id == 0);
+        ERR("No MaterialIDs given in the mesh therefore default material id = "
+            "0 is used.");
+    }
+    auto keys = media_ | ranges::views::keys;
+
+    if (media_.size() == 1)
+    {
+        ERR("Single medium for material id {} is defined.",
+            fmt::join(keys, ", "));
+    }
+    else
+    {
+        ERR("Media for material ids {} are defined.", fmt::join(keys, ", "));
+    }
+    OGS_FATAL("No medium for material id {} found for element {}.", material_id,
+              element_id);
 }
 
 void MaterialSpatialDistributionMap::checkElementHasMedium(
diff --git a/Tests/Data/Elliptic/cube_1x1x1_SteadyStateDiffusion/cube_1e4_anisotropic.prj b/Tests/Data/Elliptic/cube_1x1x1_SteadyStateDiffusion/cube_1e4_anisotropic.prj
index 6ee8e360caaeff7e17a409206a495b5befad9ea0..0b668684a10f0de06c7b20a0b861bf8e804f351b 100644
--- a/Tests/Data/Elliptic/cube_1x1x1_SteadyStateDiffusion/cube_1e4_anisotropic.prj
+++ b/Tests/Data/Elliptic/cube_1x1x1_SteadyStateDiffusion/cube_1e4_anisotropic.prj
@@ -16,7 +16,7 @@
         </process>
     </processes>
     <media>
-        <medium id="0,1,2">
+        <medium id="*">
             <properties>
                 <property>
                     <name>diffusion</name>
diff --git a/Tests/Data/HydroMechanics/ExcavationNiches/excavation_niches.prj b/Tests/Data/HydroMechanics/ExcavationNiches/excavation_niches.prj
index 2aa4c890ada924ad40c8ab20aa83723d66730ead..db8844f15f14887b84031de2fd5cbfcca680414b 100644
--- a/Tests/Data/HydroMechanics/ExcavationNiches/excavation_niches.prj
+++ b/Tests/Data/HydroMechanics/ExcavationNiches/excavation_niches.prj
@@ -30,7 +30,7 @@
         </process>
     </processes>
     <media>
-        <medium id="0,1,2">
+        <medium id="*">
             <phases>
                 <phase>
                     <type>AqueousLiquid</type>
diff --git a/Tests/Data/Parabolic/LiquidFlow/RasterParameter/GroundwaterModelWithRasterBC.prj b/Tests/Data/Parabolic/LiquidFlow/RasterParameter/GroundwaterModelWithRasterBC.prj
index c9f6f597ac42cc0461808d34d10e46ff156accb3..bc7ff29704898755b3881321f5b8953989ed8fcb 100644
--- a/Tests/Data/Parabolic/LiquidFlow/RasterParameter/GroundwaterModelWithRasterBC.prj
+++ b/Tests/Data/Parabolic/LiquidFlow/RasterParameter/GroundwaterModelWithRasterBC.prj
@@ -26,7 +26,7 @@
         </process>
     </processes>
     <media>
-        <medium id="0,1,2,3,4,5,6,7,8,9">
+        <medium id="*">
             <phases>
                 <phase>
                     <type>AqueousLiquid</type>
diff --git a/Tests/Data/ThermoHydroMechanics/HeatingHomogeneousDomain/hex_THM.prj b/Tests/Data/ThermoHydroMechanics/HeatingHomogeneousDomain/hex_THM.prj
index 0036222525f57a40c70ffdfc14541943143764ff..a178272dc13193e52190a2d84e5447ae83420b8e 100644
--- a/Tests/Data/ThermoHydroMechanics/HeatingHomogeneousDomain/hex_THM.prj
+++ b/Tests/Data/ThermoHydroMechanics/HeatingHomogeneousDomain/hex_THM.prj
@@ -33,7 +33,7 @@
         </process>
     </processes>
     <media>
-        <medium id="0">
+        <medium id="*">
             <phases>
                 <phase>
                     <type>AqueousLiquid</type>