(?:^|\s)((?:[^h ]|h(?!elp))+\/pdf\/\S*)(?:$|\s)
First thing is match either a space or the start of a line
(?:^|\s)
Then we match anything that is not a
or h
OR any h
that does not have elp
behind it, one or more times +
, until we find a /pdf/
, then match non-space characters \S
any number of times *
.
((?:[^h ]|h(?!elp))+\/pdf\/\S*)
If we want to detect help
after the /pdf/
, we can duplicate matching from the start.
((?:[^h ]|h(?!elp))+\/pdf\/(?:[^h ]|h(?!elp))+)
Finally, we match a
or end line/string ($
)
(?:$|\s)
The full match will include leading/trailing spaces, and should be stripped. If you use capture group 1, you don't need to strip the ends.
Example on regex101