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

  • Home
  • SEARCH
  • 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 7032143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:53:46+00:00 2026-05-28T00:53:46+00:00

Reg ex again. Trying to run a like SQL query: mysql_query(SELECT * From tablename

  • 0

Reg ex again.

Trying to run a like SQL query:

mysql_query("SELECT * From tablename WHERE somthing LIKE '%id|length:3:\"{$id}\"%'");

problem is the length value will be unknown, only the ID.

Of course, I could use strlen($id) and do this:

$len = intval(strlen($id));
mysql_query("SELECT * From tablename WHERE somthing LIKE '%id|length:{$len}:\"{$id}\"%'");

But I dont really care to check the len value, there’s gotta be a bit of Reg ex to match anything where the length will be and sort this without having to calc the length before.

mysql_query("SELECT * From tablename WHERE somthing LIKE '%id|length:^*:\"{$id}\"%'");

ideas?

  • 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-28T00:53:47+00:00Added an answer on May 28, 2026 at 12:53 am

    @Naddiseo’s link is a good one, I recommend you use REGEXP. What do you mean by ‘No exact example matching’?

    Try something like (I added in the newlines for readability):

    mysql_query("SELECT * From tablename 
                 WHERE somthing 
                 REGEXP '^.*id\\\|length:[0-9]+:\"{$id}\".*$'");
    

    The relevant regex without worrying about escaping for MYSQL/php strings is

    ^.*id\|length:[0-9]+:"abc".*$
    

    (assuming abc is a particular ${id}).

    It says, “look for anything followed by the literal string id|length: (I’ve escaped it as | has a special meaning in regex and you want literal |), followed by numbers ([0-9]+) being the length of the id, followed by :"{$id}" and anything else (where {$id} has been substituted in).

    Now, if you read the MySQL regexp page that @Naddiseo quoted, you’d see that any backslashes need to be further escaped as MySQL parses backslashes as special characters.

    So, if you were to enter this query into a MySQL command line (let’s assume {$id} is abc for now), you’d have to type:

    SELECT * From tablename 
      WHERE somthing 
      REGEXP '^.*id\\|length:[0-9]+:"abc".*$'
    

    Now, since you are calling this from PHP inside double quotes, you need to escape your backslashes again to make sure the right number get through to MySQL, as well as backslashing your double quotes to escape them. Hence the three backslashes in the mysql_query above before the |.

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

Sidebar

Related Questions

I have problem with reg ex. in PHP I have string like: sdfsfds dsfdsh
I need a reg exp that will parse something like- 2 * 240pin where
I'd like a reg exp which can take a block of string, and find
I am trying to retrieve some values from the registry. Here is the full
I have two pages like reg.php and profile.php. in reg.php have a field gender
I'm trying to learn reg exp, i want to get title of <img only
function validation(reg) { str = document.reg; if (str.name.value == ) { alert(Enter your name);
I want a reg exp for generating SEO-friendly URLs, so things like: My product
There is a REG_MULTI_SZ value that I would like to stick in an array
I have a small Problem using reg. expressions with scanner here's the code: String

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.