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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:37:17+00:00 2026-06-16T00:37:17+00:00

Please note that I want to find special character in string other that what

  • 0

Please note that I want to find special character in string other that what i specify.

DECLARE @Temp1 NVARCHAR(100)
SET @Temp1 ='Rajesh[sdf]' 
SELECT PATINDEX('%[^0-9A-Za-z .&()[[,''-]%',@Temp1)

After a long finding I got for allowing left square bracket we have to put two times [ i.e [[
But this is not the case for right bracket
The Expression PATINDEX(‘%[^0-9A-Za-z .&()[[],”-]%’,@Temp1) does not give the proper result expected.

DECLARE @Temp1 NVARCHAR(100)
SET @Temp1 ='Rajesh[sdf]' 
SELECT PATINDEX('%[^0-9a-z .&()[[],''-]%',@Temp1)

Above code returns patindex 0 as I have removed uppercase . It should return 1 For match for ‘R’. So what is right match for right bracket.

  • 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-16T00:37:18+00:00Added an answer on June 16, 2026 at 12:37 am

    Per this link, it looks like [[ is not the escape for [ but rather [[]. In other words, a left square bracket within a left-right square bracket pair.

    This being the case, your PATINDEX should be as follows.

    PATINDEX('%[^0-9A-Za-z .&()[[]],''-]%',@Temp1)
    

    Notice the additional ] since the first ] closes out the [] pair to match [.

    EDIT #1:

    What if you were to try something like this? What we’re doing is first replacing the bothersome [] characters with () and then doing your search for special characters not in your list.

    DECLARE @Temp1 NVARCHAR(100)
    SET @Temp1 ='Rajesh[sdf]'
    SET @Temp1 = REPLACE(@Temp1,'[','(')
    SET @Temp1 = REPLACE(@Temp1,']',')')
    SELECT PATINDEX('%[^0-9A-Za-z .&(),''-]%',@Temp1)
    

    Unfortunately, I can’t test this at this time because I don’t have a working copy of SQL Server right this second. I will try to test in a bit once I get one installed.

    EDIT #2:

    Now that I’ve been able to test, I’ve confirmed this as a possible solution.

    DECLARE @Temp1 NVARCHAR(100)
    SET @Temp1 ='Rajesh[sdf]+'
    SET @Temp1 = REPLACE(@Temp1,'[','.')
    SET @Temp1 = REPLACE(@Temp1,']','.')
    SET @Temp1 = REPLACE(@Temp1,'-','.')
    SELECT PATINDEX('%[^0-9a-z .&(),'']%',@Temp1 COLLATE Latin1_General_BIN)
    

    There were several challenges that needed to be overcome.

    • The code page for my database was case-insensitive (SQL_Latin1_General_CP1_CI_AS). I needed to use COLLATE to get around this. Note that I used the BIN collation because even the CS collation didn’t behave as expected. This fixed the problem where removing A-Z still wouldn’t match on R.
    • The - character from the original PATINDEX expression was not working correctly. This is probably because it is a special character in the expression (i.e. “through” in a-z). I tried escaping it like -- and while this worked, my additional test case of a + was broken. I found this really odd, but in the end decided it might be easier to just substitute - with another character I knew I was going to reject (.).
    • The string REPLACE functions reduces the complexity of the PATINDEX (and makes it actually work) by removing the offending special characters from the expression completely. Assuming you’ll always have at least one character you’re rejecting in the PATINDEX, using these REPLACE expressions should be a workable solution. In theory it will slow things down a bit, but that’s something that will just have to be tested in real-life to see if it matters any.

    I know that this solution works as I’ve been able to test it. Just needed a little bit of time to get SQL Server Express Edition up and running!

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

Sidebar

Related Questions

Please note that I want the compartment number to change. <?php $compartment = 1;
Please note that I'm not asking how but why. And I don't know if
[Please note that this is a different question from the already answered How to
(Please note that I have seen a similar question on StackOverflow recently, however I
Please note that this is not homework and i did search before starting this
Please note that I did ask this on Super User and received absolutely no
Please note that this question is from 2008 and now is of only historic
Can I write XSD schema for this? Please note that the category is repeated
How can I convert Persian date to Gregorian date using System.globalization.PersianCalendar? Please note that
When open a query in Microsoft project, the start date changes. Please note that,

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.