Jump to content

[SOLVED] "WHERE expr REGEXP pat" Creating Unexpected Error


labiere

Recommended Posts

I am trying to select a subset of rows from a table based on a text pattern.

My table column, labeled "id", has entries like this:

 

  • xx2
  • xx38
  • xxy2

(These items are always made up of 1 or more letters followed by one or more numbers)

 

I have defined a PHP variable $prefix="xx"

I want to perform a query that will select the two "xx" rows, but not the "xxy" row.

 

When I try the query like this, I get all three rows back, as I would expect:

// Performing SQL query
$query2 = "SELECT * FROM table WHERE id REGEXP '^$prefix'";

 

I thought this change would give me rows that start with "xx" immediately followed by a digit:

// Performing SQL query
$query2 = "SELECT * FROM table WHERE id REGEXP '^$prefix[0-9]'";

 

.. What I get with that change is an error message: Parse error: syntax error, unexpected '-', expecting ']'

 

Been banging my head over it for a while now.. Any ideas?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.