Home > Enterprise >  Extract text up to the n-th character in a string, but return the whole string if the character isn&
Extract text up to the n-th character in a string, but return the whole string if the character isn&

Time:03-08

I was looking at enter image description here

CodePudding user response:

You can repeat matching 0-3 times including the > using

^(?:[^>]*>){0,3}[^>]*
  • ^ Start of string
  • (?:[^>]*>){0,3} Repeat 0 - 3 times matching any character except > and then match >
  • [^>]* Optionally match any char except >

See a regex demo.

If there should be at least a single > then the quantifier can be {1,3}

  • Related