Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Codeigniter Query Builder using MySQL and REGEX with word boundaries adds extra space

With this issue, I would really like to avoid modifying the core files if possible, so a workaround would be extremely helpful.

REGEX works with the 'where' query builder class easy enough, but using the word boundaries breaks it by adding an extra space.

function search($searchQuery){
    $sq = '[[:<:]]'.strtolower($searchQuery).'[[:>:]]';
    $this->db->select('column');
    $this->db->from('table');
    $this->db->where('LOWER(otherColumn) REGEXP', $sq);
    echo $this->db->get_compiled_select();
}

search('billy');

Expected result:

SELECT column FROM table WHERE LOWER(otherColumn) REGEXP '[[:<:]]billy[[:>:]]';

Actual result:

SELECT column FROM table WHERE LOWER(otherColumn) REGEXP [[: < :]]billy[[:>:]]';

This is such a specific issue with a specific stack and I haven't found anybody running into the same issue. I've tried escaping the colons, the <'s, the square brackets, nothing seems to work. Or it adds additional backslashes.

Really any help or direction would be helpful at this point.

Thanks in advance.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

function search($searchQuery){
    $sq = $this->db->escape('[[:<:]]'.strtolower($searchQuery).'[[:>:]]');
    $this->db->select('column');
    $this->db->from('table');
    $this->db->where('LOWER(otherColumn) REGEXP ', $sq, false); 
    echo $this->db->get_compiled_select();
}

search('billy');

For Codeigniter v 3.1.6 and MySQL v5.6


Just because Codeigniter adds space before and after < when compiling the query, I do not know why but it does. And I have escaped the value for variable $sq to mitigate injection Attack or identical. Hence, added third parameter to where function as false to prevent it from re-escaping and adding spaces.

I have not gone through other versions of codeigniter. I hope this will work.

For more information on MySQL REGEXP visit this link: MySQL 5.6 Reference Manual - Regular Expressions

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!