diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php
index ba36047a98ad88b7cf775c56edc97f432750a4b0..61081c06fecd90b4225b040a4bd4addfe1c1b704 100644
--- a/lib/SimpleSAML/Configuration.php
+++ b/lib/SimpleSAML/Configuration.php
@@ -335,7 +335,7 @@ class SimpleSAML_Configuration {
 	
 	
 	public function getBaseURL() {
-		if (preg_match('/^\*(.*)$/', $this->getString('baseurlpath', 'simplesaml/'), $matches)) {
+		if (preg_match('/^\*(.*)$/D', $this->getString('baseurlpath', 'simplesaml/'), $matches)) {
 			return SimpleSAML_Utilities::getFirstPathElement(false) . $matches[1];
 		}
 
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index ea3913029a5976cea3a5219ed96e6931559f3694..dea9998d59c22d34e52d5e141015b4155d77e5a6 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -472,7 +472,7 @@ class SimpleSAML_Utilities {
 		assert('is_null($timestamp) || is_int($timestamp)');
 
 		/* Parse the duration. We use a very strict pattern. */
-		$durationRegEx = '#^(-?)P(?:(?:(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?)|(?:(\\d+)W))$#';
+		$durationRegEx = '#^(-?)P(?:(?:(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?)|(?:(\\d+)W))$#D';
 		if (!preg_match($durationRegEx, $duration, $matches)) {
 			throw new Exception('Invalid ISO 8601 duration: ' . $duration);
 		}
diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index d7716b5af7add2b5b337355f2d25120b6f3fa8fd..b0460e5bea3d0baa048ac79a58542e0a30c91833 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -252,7 +252,7 @@ class SimpleSAML_XHTML_Template {
 		}
 
 		/* Check whether we should use the default dictionary or a dictionary specified in the tag. */
-		if(substr($tag, 0, 1) === '{' && preg_match('/^{((?:\w+:)?\w+?):(.*)}$/', $tag, $matches)) {
+		if(substr($tag, 0, 1) === '{' && preg_match('/^{((?:\w+:)?\w+?):(.*)}$/D', $tag, $matches)) {
 			$dictionary = $matches[1];
 			$tag = $matches[2];
 		} else {
diff --git a/modules/casserver/www/serviceValidate.php b/modules/casserver/www/serviceValidate.php
index 4b767ede7a5246b0ff9cbfa09ba51f9be7df912c..dde96ade3ae7277c9c50a3a1bd3835d18f6c1c6a 100644
--- a/modules/casserver/www/serviceValidate.php
+++ b/modules/casserver/www/serviceValidate.php
@@ -91,7 +91,7 @@ function storeTicket($ticket, $path, &$value ) {
 
 function retrieveTicket($ticket, $path) {
 
-	if (!preg_match('/^_?[a-zA-Z0-9]+$/', $ticket)) throw new Exception('Invalid characters in ticket');
+	if (!preg_match('/^_?[a-zA-Z0-9]+$/D', $ticket)) throw new Exception('Invalid characters in ticket');
 
 	if (!is_dir($path)) 
 		throw new Exception('Directory for CAS Server ticket storage [' . $path . '] does not exists. ');
diff --git a/modules/casserver/www/validate.php b/modules/casserver/www/validate.php
index 9d01c5a8483ca28c86dc27eaf60acff9a518435c..27e847efea182ea2e9261e7cdd6948943b20698a 100644
--- a/modules/casserver/www/validate.php
+++ b/modules/casserver/www/validate.php
@@ -72,7 +72,7 @@ function storeTicket($ticket, $path, &$value ) {
 
 function retrieveTicket($ticket, $path) {
 
-	if (!preg_match('/^_?[a-zA-Z0-9]+$/', $ticket)) throw new Exception('Invalid characters in ticket');
+	if (!preg_match('/^_?[a-zA-Z0-9]+$/D', $ticket)) throw new Exception('Invalid characters in ticket');
 
 	if (!is_dir($path)) 
 		throw new Exception('Directory for CAS Server ticket storage [' . $path . '] does not exists. ');
diff --git a/modules/logpeek/www/index.php b/modules/logpeek/www/index.php
index fbc5688a7629c7c22441cb255883bfd1eaa327f5..2389e31ea28f8a5fa41fd623fae4e8af4157c38b 100644
--- a/modules/logpeek/www/index.php
+++ b/modules/logpeek/www/index.php
@@ -1,7 +1,7 @@
 <?php
 
 function logFilter($objFile, $tag, $cut){
-	if (!preg_match('/^[a-f0-9]{10}$/', $tag)) throw new Exception('Invalid search tag');
+	if (!preg_match('/^[a-f0-9]{10}$/D', $tag)) throw new Exception('Invalid search tag');
 	
 	$i = 0;
 	$results = array();
diff --git a/www/admin/test.php b/www/admin/test.php
index 29905e6d1ad0951ff4d3658e93b7ff22fef989bc..cea34faf24fb84688b7eccd847f337490f237cac 100644
--- a/www/admin/test.php
+++ b/www/admin/test.php
@@ -67,7 +67,7 @@ if (array_key_exists('protocol', $_GET)) {
 $attr_test = array();
 
 foreach ($_GET as $k => $v) {
-	if(preg_match('/^attr_test(?:_\d+)?$/', $k)) {
+	if(preg_match('/^attr_test(?:_\d+)?$/D', $k)) {
 		$pos = strpos($v, ':');
 		if($pos === FALSE) {
 			error('Invalid attribute test: $v');
diff --git a/www/auth/login-feide.php b/www/auth/login-feide.php
index 8439c9aca87546ad2ee78c4bf4a53746750569ff..1680ee149ab01fdd16a53c270478d7ef5bb6ec7c 100644
--- a/www/auth/login-feide.php
+++ b/www/auth/login-feide.php
@@ -121,7 +121,7 @@ if (isset($_REQUEST['username'])) {
 		/*
 		 * Checking username parameter for illegal characters.
 		 */
-		if (!preg_match('/^[a-z0-9._]+(@[a-z0-9._]+)?$/', $requestedUser) ) 
+		if (!preg_match('/^[a-z0-9._]+(@[a-z0-9._]+)?$/D', $requestedUser) ) 
 			throw new Exception('Illegal characters in (or empty) username.');
 		
 		/*
@@ -143,7 +143,7 @@ if (isset($_REQUEST['username'])) {
 			$requestedOrg = strtolower($_REQUEST['org']);
 		}
 
-		if (!preg_match('/^[a-z0-9.]*$/', $requestedOrg) ) 
+		if (!preg_match('/^[a-z0-9.]*$/D', $requestedOrg) ) 
 			throw new Exception('Illegal characters in organization.');
 
 		if (!array_key_exists($requestedOrg, $ldaporgconfig))
@@ -159,7 +159,7 @@ if (isset($_REQUEST['username'])) {
 		
 		$password = $_REQUEST['password'];
 		
-		if (!preg_match('/^[a-zA-Z0-9.]+$/', $password) ) 
+		if (!preg_match('/^[a-zA-Z0-9.]+$/D', $password) ) 
 			throw new Exception('Illegal characters in password.');
 		
 		/*
diff --git a/www/module.php b/www/module.php
index 649b95c82f748d6d4bb4bf0256dbeda493eb613b..12bf3b5cb1fbddbb522d426f2ffa8aad22415d1f 100644
--- a/www/module.php
+++ b/www/module.php
@@ -129,7 +129,7 @@ try {
 		throw new SimpleSAML_Error_NotFound('The URL wasn\'t found in the module.');
 	}
 
-	if (preg_match('#\.php$#', $path)) {
+	if (preg_match('#\.php$#D', $path)) {
 		/* PHP file - attempt to run it. */
 		$_SERVER['SCRIPT_NAME'] .= '/' . $module . '/' . $url;
 		require($path);
@@ -140,7 +140,7 @@ try {
 
 	/* Find MIME type for file, based on extension. */
 	$contentType = NULL;
-	if (preg_match('#\.([^/]+)$#', $path, $type)) {
+	if (preg_match('#\.([^/]+)$#D', $path, $type)) {
 		$type = strtolower($type[1]);
 		if (array_key_exists($type, $mimeTypes)) {
 			$contentType = $mimeTypes[$type];