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 366827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:40:10+00:00 2026-05-12T13:40:10+00:00

I have the following table Table bots{ ip_address varchar(15), bot_name varchar(32) } Given that

  • 0

I have the following table

Table bots{
    ip_address varchar(15),
    bot_name varchar(32)
}

Given that some bots have static ips and others won’t, the table has entries such as 192.168.0 and 192.168.1.15

Now I have to see if a given ip belongs to a bot. I was thinking something along these lines

SELECT bot_name
FROM bots
WHERE __input_ip__  REGEXP '^ip_address'

but this won’t work for the obvious reason that it is looking for a string that starts with ip_address.

So my question is, how can I include a field name within a sql regular expression ?

  • 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-05-12T13:40:11+00:00Added an answer on May 12, 2026 at 1:40 pm

    You might want to consider storing the IP address as an INT UNSIGNED. Also store the netmask so you can tell the difference between a static address and a subnet.

    INSERT INTO bots (ipaddress, netmask, bot_name) 
    VALUES (INET_ATOI('192.168.1.0'), INET_ATOI('255.255.255.0'), 'Wall-E');
    

    Then you can query to see if an input IP address matches:

    SELECT bot_name
    FROM bots
    WHERE __input_ip__ & netmask = ipaddress & netmask;
    

    Using integers for IP addresses instead of CHAR(15) is a common optimization. Even storing the 8 bytes for the IP address and the netmask is little more than half the storage of the CHAR(15). And the bitwise operations are likely to be a lot faster than the regular expression matching, and it’s easier to avoid the corner cases like in @Gumbo’s comment.

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

Sidebar

Related Questions

I have the following table drop table names; create table names( name varchar(200), surname
I have the following table that lists all awarded cups: Name: Cups Columns: Month,
I have following table structure: CREATE TABLE pilot_groups ( id INT PK, name VARCHAR(50),
I have the following table (let's say that its name is AnswerTable: QuestionID Value
I have following table with some rows and want to disable the all the
given the following table descriptions: emp : ename varchar2(25) dept: loc varchar2(25) I have
I have following table where each row has a unique ID. Now I want,
I have following table structure. town: id (MEDINT,PRIMARY KEY,autoincrement), town(VARCHAR(150),not null), lat(FLOAT(10,6),notnull) lng(FLOAT(10,6),notnull) i
I have following table structures: Item: ----------------------- item_id INT (PRIMARY), category_id MEDIUMINT, name VARCHAR(40)
I have following table structure there is column vid in that i want entry

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.