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

Time:07-12

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.

CodePudding user response:

Use this:

^[^/]{10,}

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

DEMO

  • Related