doubt on reliability of Java REGEX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    doubt on reliability of Java REGEX

    Good day

    Is it safe to use java regex to extract links and email addresses of a specific webpage?(this is not intended for malicious activity)

    We are on the final stage in college, and we have already proposed a project that needs an extraction tool, we decided to create our own(we still have 3 weeks to decide whether to hardcode it or to use 3rd party libraries for parsing html)

    Im doubt to choose whether to use the java regular expression or other 3rd party html parsers due to some articles like this one.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by sukatoa
    Good day

    Is it safe to use java regex to extract links and email addresses of a specific webpage?(this is not intended for malicious activity)

    We are on the final stage in college, and we have already proposed a project that needs an extraction tool, we decided to create our own(we still have 3 weeks to decide whether to hardcode it or to use 3rd party libraries for parsing html)

    Im doubt to choose whether to use the java regular expression or other 3rd party html parsers due to some articles like this one.
    Regular expressions in Java are reliable but limited to regular languages. HTML isn't a regular language. I use the word 'regular' in a theoretical way. One of the limitations is that regular languages (and so regular expressions) can not find nested structures easily. You need full fledged parsers for that. The SAX parser implemented in Java is such a parser. Email addresses don't contain nested structures and can be parsed by regular expressions. Google for some of them, there are a lot around on the net.

    My advice would be to use a SAX parser to retrieve the possible pieces of text out of an HTML text and parse those pieces with a regular expression to determine whether or not it actually can be a valid email address.

    kind regards,

    Jos

    Comment

    • sukatoa
      Contributor
      • Nov 2007
      • 539

      #3
      Thanks for your advice Jos :)

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by sukatoa
        Thanks for your advice Jos :)
        You're welcome of course and good luck with your project.

        kind regards,

        Jos

        Comment

        Working...