Let me preface this with I am pretty noob at doing regex. The code I am writing is for macOS, not iOS but I don't think that matters in this case. I'm trying to search a git diff return based on the change range indicators. Here's is the content I am searching (the variable is called element):
3b8d5178f4d21e9269547e8f0bae4b7daa7d8206
Author: Steve <[email protected]>
Date: Fri Oct 4 16:55:50 2019 -0400
Fixed responsiveness of code blocks
diff --git a/examples/video/outstream/pb-ve-outstream-no-server.html b/examples/video/outstream/pb-ve-outstream-no-server.html
index ae813578..e18e31ec 100644
--- a/examples/video/outstream/pb-ve-outstream-no-server.html
+++ b/examples/video/outstream/pb-ve-outstream-no-server.html
@@ -24,7 +24,7 @@ sidebarType: 4
<div>
- <div>
+ <div style="width:60vw;">
<p>Lorem ipsum dolor sit ....</p>
</div>
@@ -33,7 +33,7 @@ sidebarType: 4
<p>Prebid Outstream Video Ad</p>
</div>
- <div>
+ <div style="width:60vw;">
<p>Sed ut perspiciatis ...</p>
</div>
</div>
@@ -49,9 +49,9 @@ sidebarType: 4
Do not forget to exchange the placementId in the code examples with your own placementId!</p>
</div>
- <div>
+ <div style="width:60vw;">
<h4>Place this code in the page header.</h4>
-<pre class="pb-code-hl">
+<pre class="pb-code-hl" style="width:60vw;">
<!--put javascript code here-->
<script>
var pbjs = pbjs || {};
@@ -95,9 +95,9 @@ sidebarType: 4
</div>
<!--body code example-->
- <div>
+ <div style="width:60vw;">
<h4>Place this code in the page body.</h4>
-<pre class="pb-code-hl">
+<pre class="pb-code-hl" style="width:60vw;">
<!--put body html and javascript here-->
<div id='video1'>
<p>Prebid Outstream Video Ad</p>
here's my regex to get the change indicators
do {
let regex = try NSRegularExpression(pattern: "@@ (.*) @@", options: .caseInsensitive)
let matches = regex.matches(in: element, options:[], range: NSRange(location: 0, length: element.utf16.count))
for match in matches {
let strElement = element as NSString
arrMatches.append(strElement.substring(with: match.range) as String)
}
} catch {
print ("Error with regex return")
}
Works as expected, I get all four instances:
["@@ -24,7 +24,7 @@", "@@ -33,7 +33,7 @@", "@@ -49,9 +49,9 @@", "@@ -95,9 +95,9 @@"]
I now want to capture the changes between the indicators. But I am not getting any results, not even an error on the catch. Here's a hard coded example of what I am trying to do:
do {
let regex = try NSRegularExpression(pattern: "@@ -24,7 +24,7 @@ (.*) @@ -33,7 +33,7 @@", options: .caseInsensitive)
let matches = regex.matches(in: element, options:[], range: NSRange(location: 0, length: element.utf16.count))
print(matches.count)//<--prints 0, expecting 1
for match in matches {
let strElement = element as NSString
print(":::" + strElement.substring(with: match.range) as String) //<--Nothing prints
}
} catch {
print ("Error with regex return")//<-but nothing prints here either...
}
The content has a lot of tabs and linebreaks so I am wondering if I somehow have to account for those within my regex? Any help would be appreciated.
I should get 4 results, the first result should be:
sidebarType: 4
<div>
- <div>
+ <div style="width:60vw;">
<p>Lorem ipsum dolor sit ....</p>
</div>
the second result would be content between change indicator 2 and 3, the third content between 3 and 4 and the last all content after 4
@@ -24,7 +24,7 @@and@@ -33,7 +33,7 @@, use"(?s)@@ -24,7 \\+24,7 @@(.*)@@ -33,7 \\+33,7 @@""@@ -24,7 \\+24,7 @@([\\S\\s]*?)@@ -33,7 \\+33,7 @@"