Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7810629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:51:13+00:00 2026-06-02T03:51:13+00:00

Is it possible to check a string with a single regex and validate it

  • 0

Is it possible to check a string with a single regex and validate it if matches valid IPv4 or IPv6 address or even a hostname with no special characters but dot (.)?

I have separate regex for IPv4 and IPv6 but how do I combine them to do the work described above?

Thanks in advance,

Dan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:51:16+00:00Added an answer on June 2, 2026 at 3:51 am

    You could use a single regex, but it’s going to be ugly as hell. Either;

    • Create separate regexes as strings, then combine them. Far more legible. Or,
    • Test each regex separately. Also much clearer.

    Perl-ish example:

    if ( $foo =~ /$ipv4_re/ or $foo =~ /$ipv6_re/ or $foo =~ /$hostname_re/ ) {
        ...
    }
    

    Having said that, there are probably libraries in Python that will validate these things for you, and personally I’d rather rely on them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Check whether the string is a unix timestamp i need validate a
Possible Duplicate: check number of a given character occurence in a String I'm trying
Is it possible to check if loaded with xmlDoc.loadXML(xmlData); xml string is invalid? For
What is the simplest and fastest way to check if string is single URL
Possible Duplicate: javascript - check if string begins with something? I've read in this
import java.util.regex.Pattern; class HowEasy { public boolean matches(String regex) { System.out.println(Pattern.matches(regex, abcABC )); return
Possible Duplicate: How to check if a string is a legal “dd/mm/yyyy” date? I
Possible Duplicate: Check if a String Ends with a Number in PHP I'm trying
In Javascript is it possible to check whether a string occurs in an array
Is it possible for one to check the strong name of a .NET application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.