MSSQL Regular expression

后端 未结 3 1666
深忆病人
深忆病人 2020-12-03 05:01

I have the following REGEX: ^[-A-Za-z0-9/.]+$

This currently checks whether the value entered into a textbox matches this. If not, it throws an error.

I need

相关标签:
3条回答
  • 2020-12-03 05:30

    Thank you all for your help.

    This is what I have used in the end:

    SELECT *, 
      CASE WHEN [url] NOT LIKE '%[^-A-Za-z0-9/.+$]%' 
        THEN 'Valid' 
        ELSE 'No valid' 
      END [Validate]
    FROM 
      *table*
      ORDER BY [Validate]
    
    0 讨论(0)
  • 2020-12-03 05:30

    Disclaimer: The original question was about MySQL. The SQL Server answer is below.

    MySQL

    In MySQL, the regex syntax is the following:

    SELECT * FROM YourTable WHERE (`url` NOT REGEXP '^[-A-Za-z0-9/.]+$') 
    

    Use the REGEXP clause instead of LIKE. The latter is for pattern matching using % and _ wildcards.


    SQL Server

    Since you made a typo, and you're using SQL Server (not MySQL), you'll have to create a user-defined CLR function to expose regex functionality.

    Take a look at this article for more details.

    0 讨论(0)
  • 2020-12-03 05:34

    As above the question was originally about MySQL

    Use REGEXP, not LIKE:

    SELECT * FROM `table` WHERE ([url] NOT REGEXP '^[-A-Za-z0-9/.]+$')
    
    0 讨论(0)
提交回复
热议问题