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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:09:33+00:00 2026-06-18T03:09:33+00:00

I’m looking for an SQL statement that will return only rows of my table

  • 0

I’m looking for an SQL statement that will return only rows of my table whose Name field contains special characters (excluding underscores).

I’ve tried:

SELECT * FROM 'table' WHERE Name REGEXP '^[!#$%&()*+,\-./:;<=>?@[\\\]^`{|}~]+$'

But no dice, this returns an empty result set (despite there being rows I specifically added with Name fields containing %, $, and # characters).

  • 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-18T03:09:34+00:00Added an answer on June 18, 2026 at 3:09 am

    The first problem seems to be is the ^ and $ signs (Mike C summarized it quicker than I did why…)

    But I see escaping problems too: all special characters that mean something in regexp should be escaped specially placed in the [], so [, ], ^, -

    Here is a question about how to escape special characters inside character groups in MySQL regexes.

    Conclusion detailed in the regex documentation:

    A bracket expression is a list of characters enclosed in ‘[]’. It normally matches any single character from the list (but see below).

    • If the list begins with ‘^’, it matches any single character (but see
      below) not from the rest of the list.

    • If two characters in the list are separated by ‘-‘, this is shorthand for the full range of characters between those two (inclusive) in the collating sequence, e.g.
      ‘[0-9]’ in ASCII matches any decimal digit.

    • It is illegal(!) for two ranges to share an endpoint, e.g. ‘a-c-e’. Ranges are very collating sequence-dependent, and portable programs should avoid relying on them.

    • To include a literal ‘]’ in the list, make it the first character (following a possible ‘^’).

    • To include a literal ‘-‘, make it the first orlast character, or the second endpoint of a range.

    • To use a literal ‘-‘ as the first endpoint of a range, enclose it in ‘[.’ and ‘.]’ to make it a collating element (see below).

    With the exception of these and some combinations using ‘[‘ (see next paragraphs), all other special characters, including ‘\’, lose their special significance within
    a bracket expression
    .

    EDIT
    Here is an SQL fiddle about some interesting regexes regarding the ] character

    DDL:
    create table txt (
    txt varchar(200)
    );

    insert into txt values ('ab[]cde');
    insert into txt values ('ab[cde');
    insert into txt values ('ab]cde');
    insert into txt values ('ab[]]]]cde');
    insert into txt values ('ab[[[[]cde');
    insert into txt values ('ab\\]]]]cde');
    insert into txt values ('ab[wut?wut?]cde');
    

    Queries:

    Naive approach to match a group of [ and ] chars. Syntactically OK, but the group is the single [ char, and it matches multiple ] chars afterwards.

    SELECT * FROM txt WHERE txt 
    REGEXP 'ab[[]]+cde';
    

    Escaped -> same ???

    SELECT * FROM txt WHERE txt 
    REGEXP 'ab[[\]]+cde';
    

    Double escape -> doesn’t work, group is now a [ and a \

    SELECT * FROM txt WHERE txt 
    REGEXP 'ab[[\\]]+cde';
    

    Swapping the closing bracket with the opening one inside the group. This is the weirdest regex I ever wrote – to this point…

    SELECT * FROM txt WHERE txt 
    REGEXP 'ab[][]+cde';
    

    I will get killed by such a (totally valid!) regex in a weird nightmare, I think:

    SELECT * FROM txt WHERE txt 
    REGEXP 'ab[]wut?[]+cde';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into

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.