Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Detect only internal links containing the rel noopener

Detect only internal links containing the rel noopener

Scheduled Pinned Locked Moved Regular Expressions
questionhtmlcomregextutorial
6 Posts 3 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15199879
    wrote on last edited by
    #1

    Hello, I would like to process a regex to look for only the internal links containing the rel="noopener" For example search for this link:

    anchor text

    In this case the regex should be:

    href="https://www.linkinterno.it(.*?)rel="noopener"

    and it should work as I checked it with the following regex test: https://www.freeformatter.com/regex-tester.html However, I am not looking for internal links correctly, only those with rel="noopener". How can I solve? Thank you ;)

    T 1 Reply Last reply
    0
    • M Member_15199879

      Hello, I would like to process a regex to look for only the internal links containing the rel="noopener" For example search for this link:

      anchor text

      In this case the regex should be:

      href="https://www.linkinterno.it(.*?)rel="noopener"

      and it should work as I checked it with the following regex test: https://www.freeformatter.com/regex-tester.html However, I am not looking for internal links correctly, only those with rel="noopener". How can I solve? Thank you ;)

      T Offline
      T Offline
      Tony Hill
      wrote on last edited by
      #2

      Try this

      href="https:\/\/www.linkinterno.it.*rel="noopener"

      I had to escape the forward slashes '/' to try it in some of the regex testers so depending on the flavour of regex you are using you may need to remove them.

      M 1 Reply Last reply
      0
      • T Tony Hill

        Try this

        href="https:\/\/www.linkinterno.it.*rel="noopener"

        I had to escape the forward slashes '/' to try it in some of the regex testers so depending on the flavour of regex you are using you may need to remove them.

        M Offline
        M Offline
        Member_15199879
        wrote on last edited by
        #3

        Thanks a lot ;) So, the concept is to find out if inside an href there is the site name (so that I can understand that it is an internal link) and that it contains the rel="noopener". I have adapted the regex to the best, modifying it like this:

        www.sito.it. * rel = "noopener"

        and removing the https: // protocol which can generate errors. Unfortunately, however, something is still wrong. I state that the regex I need for a seo spider (ScreamingFrog), in which it is possible to set the targeted regex for searches within a website. I await your clarifications on this. Thanks a lot ;)

        T L 2 Replies Last reply
        0
        • M Member_15199879

          Thanks a lot ;) So, the concept is to find out if inside an href there is the site name (so that I can understand that it is an internal link) and that it contains the rel="noopener". I have adapted the regex to the best, modifying it like this:

          www.sito.it. * rel = "noopener"

          and removing the https: // protocol which can generate errors. Unfortunately, however, something is still wrong. I state that the regex I need for a seo spider (ScreamingFrog), in which it is possible to set the targeted regex for searches within a website. I await your clarifications on this. Thanks a lot ;)

          T Offline
          T Offline
          Tony Hill
          wrote on last edited by
          #4

          Without knowing what the internal link actually looks like it is difficult to help. Assuming that an internal link looks like this href="/2018/titolo" You could try this

          .*href=("https:\/\/www.linkinterno.it|"\/).*(rel="noopener").*

          You would obviously have to check the first group to see if the 'https://'www.linkinterno.it"' was matched or just the '/' and then look at the second group to see if the rel="noopener" was matched.

          M 1 Reply Last reply
          0
          • T Tony Hill

            Without knowing what the internal link actually looks like it is difficult to help. Assuming that an internal link looks like this href="/2018/titolo" You could try this

            .*href=("https:\/\/www.linkinterno.it|"\/).*(rel="noopener").*

            You would obviously have to check the first group to see if the 'https://'www.linkinterno.it"' was matched or just the '/' and then look at the second group to see if the rel="noopener" was matched.

            M Offline
            M Offline
            Member_15199879
            wrote on last edited by
            #5

            Thanks for the reply, I tried but all links containing rel noopener are searched. I'm interested in searching for internal links only, and can be recognized by the name of the site in the link. For example, if the site is https://www.sitoprova.it, in href there must be the name of the site at the beginning of the link, i.e.

            1 Reply Last reply
            0
            • M Member_15199879

              Thanks a lot ;) So, the concept is to find out if inside an href there is the site name (so that I can understand that it is an internal link) and that it contains the rel="noopener". I have adapted the regex to the best, modifying it like this:

              www.sito.it. * rel = "noopener"

              and removing the https: // protocol which can generate errors. Unfortunately, however, something is still wrong. I state that the regex I need for a seo spider (ScreamingFrog), in which it is possible to set the targeted regex for searches within a website. I await your clarifications on this. Thanks a lot ;)

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              With the sample text-strings you've provided, its impossible for any expression to match by 'internal' domain. If your application has a %variable% to represent the domain being searched, you would have to provide this. Regex simply matches text, it cant determine if that text is "the domain being searched" by your application. I've seen apps that support variables like %domain% in their match-expressions, but they're specific to that application. So if your app supports this, you'd have to look up the variable-name in the documentation, to provide a working example. Short of that, you would need to either hard-code the domains per site being searched, like in the example provided. Or include a larger snippet of the html, but only if the html offered another way to verify 'internal' (highly unlikely). Sorry for the news, but regex wont solve this without 'internal' being defined, whether by a previous match, or by some variable. Some apps even let you customize variables, so maybe thats another option? Sorry, but I know nothing of this "Screaming Frog". Either way, I do wish you luck!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups