+ 4

Javascript string match p tag with minmum characters

I have a html document which contains multiple p tag paragraphs. How can I use string match method with regex to find p tag with minimum characters of 50? <p>{min chars of 50 without <p>...</p> inside }</p> The output characters can be any alphanumerical letters, but cannot contain another <p> and </p> tags inside. https://code.sololearn.com/W70gt7j4jceP/?ref=app

16th Oct 2019, 3:14 PM
Calviղ
Calviղ - avatar
5 Respostas
+ 4
You can set the minimum amount of characters like this: .{50,} It works like this: {min, max}. Since the maximum amount is left out, there is bo maximum limit, only minimum. If you don't use a comma, you will match exactly 50 characters, which might not be good The second problem (it's not really a problem here, just be aware) you are having is "greediness". You want to match as few characters as possible (not including multiple p tags), and to make it non-greedy, you have to use a ?. So, your regular expressions is: /<p>.{50, }?<\/p>/gm (or as a string, without the backslash before the slash)
16th Oct 2019, 4:33 PM
Airree
Airree - avatar
+ 4
Thank you all, it really helps to solve my issue..👍
17th Oct 2019, 5:54 AM
Calviղ
Calviղ - avatar
+ 3
as for the second problem i comes up with this <p>((?!<p>)(?!</p>).){50,}</p> its using negative lookahead, but its so bulky and i havent done any test to it.
16th Oct 2019, 4:47 PM
Taste
Taste - avatar
+ 3
RegExr - regular expression playground. https://regexr.com/4mvoh (?<=<p>)(.{50,})(?=<\/p>)
16th Oct 2019, 6:57 PM
ODLNT
ODLNT - avatar
+ 1
Justin Please delete the spam messages, before I report your account to Sololearn admin. You've been warned.
29th Oct 2019, 10:11 AM
Calviղ
Calviղ - avatar