Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I preg_match a character-run of individual characters?
    primarykey
    data
    text
    <p>Using</p> <pre><code>(a{4,}) </code></pre> <p>I can match 4 or more of a specific characters in a row</p> <blockquote> <p>a aaa <strong>aaaaaa</strong> aa</p> </blockquote> <p>and with</p> <pre><code>([0-9]{4,}) </code></pre> <p>I can match 4 or more of a specific group of characters in a row</p> <blockquote> <p>1 123 <strong>1234321</strong> 12</p> </blockquote> <p>But I'm looking for a way to catch runs of an individual character in a string of characters. Meaning: I have a collection of strings in the range <code>[a-zA-z0-9]</code>. Whenever one of these characters is repeated more than 4 times, the regex should match up. </p> <p>To give you a more practical example: in... </p> <blockquote> <p>This is Teeeeeeest version 1.0.33333.4</p> </blockquote> <p>...it should be able to match the run of the <code>e</code> character and the run of the <code>3</code> character.</p> <p>Now, the following clearly doesn't satisfy my needs...</p> <pre><code>([a-zA-Z0-9]{4,}) </code></pre> <p>...since it would simply catch all runs of the allowed chars. But I only need to catch the moments where a single character is repeated 4 or more times.</p> <p>I really want to avoid looping all 64 possible characters through individual regexes with a <code>for(...)</code> and I'm sure there <em>"must be a way"</em> to do it with one regex. But since I've tried near to everything and I'mm close to hitting my head against the wall, I opted-in to hope that someone can help me with this by pushing me in the right direction.</p> <p>How can I <code>preg_match</code> a character-run of individual characters? (aka: What would the regex look like?)</p> <p><strong>EDIT (after accepting answer)</strong></p> <p>Thanks for your answer(s) and comment(s),because the only option I found to do what I wanted was</p> <blockquote> <p>(a{4,}|b{4,}|c{4,}|d{4,}|e{4,}|f{4,}|g{4,}|h{4,}|i{4,}|j{4,}|k{4,}|l{4,}|m{4,}|n{4,}|o{4,}|p{4,}|q{4,}|r{4,}|s{4,}|t{4,}|u{4,}|v{4,}|w{4,}|x{4,}|y{4,}|z{4,}|A{4,}|B{4,}|C{4,}|D{4,}|E{4,}|F{4,}|G{4,}|H{4,}|I{4,}|J{4,}|K{4,}|L{4,}|M{4,}|N{4,}|O{4,}|P{4,}|Q{4,}|R{4,}|S{4,}|T{4,}|U{4,}|V{4,}|W{4,}|X{4,}|Y{4,}|Z{4,}|0{4,}|1{4,}|2{4,}|3{4,}|4{4,}|5{4,}|6{4,}|7{4,}|8{4,}|9{4,})</p> </blockquote> <p>but that just didn't feel good... and it sure doesn't look <em>healthy</em> either, does it? ;)</p> <p>Anyway, I ended up with this...</p> <pre><code>preg_match_all('#([a-zA-Z0-9])\1{3}#', 'This is Teeeeeeest version 1.0.33333.4', $matches)); var_dump($matches); </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