Search code examples
regexstringstring-length

Regex Expression to match X or more characters until first forward slash


Trying to check a string like this:

Product Title Here / Something / Something else

I want to isolate the first string before the first / and then see how long it is and only match if it is longer than 10 characters (including spaces).

So split the string by / and then see if it can iterate 10 or more times? Sorry I am new at Regex!

My failed attempt:

.+?(?=\/){10,}

So it should isolate "Product Title Here" and return match if that is longer than 10 characters.


Solution

  • Use this:

    ^[^/]{10,}
    

    [^/] matches anything except /, and {10,} requires it to be at least 10 characters long.

    DEMO