Question: There is a string: "python php ruby javascript jsonp perhapsphpisoutdated"
For this string, use pure regular expression to get all words with p but not ph
Output array [ 'python', 'javascript', 'jsonp' ]
I have been thinking about this problem for a long time and I have no idea
My solution is
<code>var result = str.match(/\b\w*(?=p)\w*\b/g) .filter((value)=>!/.*(?=ph)/.test(value)) var result2 = str.match( /\b((?!ph|\s).)*((p[^h\s]((?!ph|\s).)*)|p)\b/g ) console.log(result2)</code>
But it does not meet the requirements of pure regularity
A big guy in the group gave this answer
<code>/\b((?!ph|\s).)*((p[^h\s]((?!ph|\s).)*)|p)\b/g </code>
Works perfectly
But I can’t understand it, I hope someone can help me understand it