Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few problems with your regex.</p> <p>First of all, as FrankeTheKneeMan pointed out, you need delimiters. <code>#</code> is a good choice for HTML matches (the standard choice is <code>/</code> but that interferes with tags too often):</p> <pre><code>'#[/*]\s*record\s*specific_number[.]specific_string1[.]specific_string2\s*[*/].*[/*]\s*record_end\s*specific_number[.]specific_string1[.]specific_string2\s*[*/]#' </code></pre> <p>Now while <code>[.]</code> is a nice way of escaping a single character, it doesn't work the same for <code>[/*]</code>. This is a character class, that matches either <code>/</code> or <code>*</code>. Same for <code>[*/]</code>. Use this instead:</p> <pre><code>'#/[*]\s*record\s*specific_number[.]specific_string1[.]specific_string2\s*[*]/.*/[*]\s*record_end\s*specific_number[.]specific_string1[.]specific_string2\s*[*]/#' </code></pre> <p>Now <code>.*</code> is the remaining problem. Actually there are too, one is critical, the other might not be. The first is that <code>.</code> does not match line breaks by default. You can change this by using the <code>s</code> (singleline) modifier. The second is, that <code>*</code> is greedy. <strong>Should</strong> a section appear twice in the string, you would get everything from the first corresponding <code>/* record</code> to the last corresponding <code>/* record_end</code>, even if there is unrelated stuff in between. Since your records seem to be very specific, I suppose this is not the case. But still it is generally good practice, to make the quantifier ungreedy, so that it consumes as little as possible. Here is your final regex string:</p> <pre><code>'#/[*]\s*record\s*specific_number[.]specific_string1[.]specific_string2\s*[*]/.*?/[*]\s*record_end\s*specific_number[.]specific_string1[.]specific_string2\s*[*]/#s' </code></pre> <p>For your presented example, this is</p> <pre><code>'#/[*]\s*record\s*863[.]content[.]en\s*[*]/.*?/[*]\s*record_end\s*863[.]content[.]en\s*[*]/#s' </code></pre> <p>If you want to find <strong>all</strong> of these sections, then you can make <code>863</code>, <code>content</code> and <code>en</code> variable, capture them (using parentheses) and use a backreference to make sure you get the corresponding <code>record_end</code>:</p> <pre><code>'#/[*]\s*record\s*(\d+)[.](\w+)[.](\w+)\s*[*]/.*?/[*]\s*record_end\s*\1[.]\2[.]\3\s*[*]/#s' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload