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

  • SEARCH
  • Home
  • 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 5978119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:28:06+00:00 2026-05-22T21:28:06+00:00

Should this regex pattern throw an exception? Does for me. ^\d{3}[a-z] The error is:

  • 0

Should this regex pattern throw an exception? Does for me.

^\d{3}[a-z]

The error is: parsing "^\d{3}[a" - Unterminated [] set.

I feel dumb. I don’t get the error. (My RegexBuddy seems okay with it.)

A little more context which I hope doesn’t cloud the issue:

I am writing this for a CLR user defined function in SQL Server:

[Microsoft.SqlServer.Server.SqlFunction(IsDeterministic=true)]
  public static SqlChars Match(
    SqlChars input,
    SqlString pattern,
    SqlInt32 matchNb,
    SqlString name,
    SqlBoolean compile,
    SqlBoolean ignoreCase,
    SqlBoolean multiline,
    SqlBoolean singleline
    )
  {
    if (input.IsNull || pattern.IsNull || matchNb.IsNull || name.IsNull)
      return SqlChars.Null; 

    RegexOptions options = RegexOptions.IgnorePatternWhitespace |
      (compile.Value ? RegexOptions.Compiled : 0) |
      (ignoreCase.Value ? RegexOptions.IgnoreCase : 0) |
      (multiline.Value ? RegexOptions.Multiline : 0) |
      (singleline.Value ? RegexOptions.Singleline : 0);

    Regex regex = new Regex(pattern.Value, options);
    MatchCollection matches = regex.Matches(new string(input.Value));

    if (matches.Count == 0 || matchNb.Value > (matches.Count-1))
      return SqlChars.Null;

    Match match = matches[matchNb.Value];

    int number;
    if (Int32.TryParse(name.Value, out number))
    {
      return (number > (match.Groups.Count - 1)) ? 
        SqlChars.Null :
        new SqlChars(match.Groups[number].Value);
    }
    else
    {
      return new SqlChars(match.Groups[name.Value].Value);
    }
  }

Setting it up with

CREATE FUNCTION Match(@input NVARCHAR(max), @pattern NVARCHAR(8), @matchNb INT, @name NVARCHAR(64), @compile BIT, @ignoreCase BIT, @multiline BIT, @singleline BIT)
RETURNS NVARCHAR(max)
AS EXTERNAL NAME [RegEx].[UserDefinedFunctions].[Match]
GO

And testing it with:

SELECT dbo.Match(
  N'123x45.6789' --@input
, N'^\d{3}[a-z]' --@pattern
,0 --@matchNb
,0 --@name
,0 --@compile
,1 --@ignoreCase
,0 --@multiline
,1 --@singleline
)
  • 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-05-22T21:28:06+00:00Added an answer on May 22, 2026 at 9:28 pm

    In your CREATE FUNCTION statement you are delcaring @pattern as NVARCHAR(8). This is truncating your pattern to 8 characters.

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

Sidebar

Related Questions

I need a regex pattern to match this format ABC12345678 : it should start
This should be straight forward for a guru. I don't have any code really
I have this regex to test for telephone # that should be a toll
I had this url regex pattern in place: $pattern = @\b(https?://[^\s()<>\[\]\{\}]{1,.$max_length_allowed_for_each_url.}(?:\([\w\d]+\)|([^[:punct:]\s]|/)))@; It seemed to
I have this regex pattern <(\d+)>(\d+\.\d+|\d{4}\-\d+\-\d+\s+\d{2}:\d{2}:\d{2})(?:\..*?)*\s+(ALER|NOTI) and this is my input (will not matched
I don't know much regex, but I need to match a simple pattern. The
I want to write the regex pattern which should match the string in between
Should this be as easy as Trace.WriteInformation() in a C# file that is in
What is the accepted practice for indenting SQL statements? How should this example be
This should be fine seeing as the CLR hasn't actually changed? The boxes running

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.