Combine regex expression with negation

I have the following string

http://google.com/q=search<p>dfgdfg</p> 

My regex looks like this :

/(((https?:\/\/)|(www\.))()[^\s]+)/g

How can I exclude the <p>dfgdfg</p>

from my string now?

I know how to search for them but I want it in combination with my regex, so I need it in negation

<\/?(p)\b[^<>]*>

Here is a playground
https://regex101.com/r/4OlCyb/1

7 thoughts on “Combine regex expression with negation”

  1. You were close. Simply add all chars to [^\s]+ that should not be in the link:

    'http://google.com/?q=search<p>dfgdfg</p>'.match(/(?:https?:\/\/|www\.)[^\s<]+/)
    

    Matches:

    http://google.com/?q=search
    

    You can add additional chars as needed to [^\s<]+

    Reply

Leave a Comment