In Sybase SQL, can multiple square brackets be avoided in a LIKE statement?

All we need is an easy explanation of the problem, so here it is.

In Sybase SQL, I have a check that looks something like this:

WHERE @v_Test LIKE "X[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]"

Is there a way to avoid having to copy the square brackets please (in this case allowing alphanumeric values but anything is possible)?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

{ and }

Left and right curly braces are metacharacters when used for specifying quantifiers. Quantifiers specify the number of times a pattern must repeat to constitute a match. For example:

{m} Matches a character exactly m times. For example, ‘519-[0-9]{3}-[0-9]{4}’ matches a phone number in the 519 area code (providing the data is formatted in the manner defined in the syntax).

{m,} Matches a character at least m times. For example, ‘[0-9]{5,}’ matches any string of five or more digits.

{m,n} Matches a character at least m times, but not more than n times. For example, SIMILAR TO ‘_{5,10}’ matches any string with between 5 and 10 (inclusive) characters.

see manual

WHERE @v_Test LIKE "X[A-Za-z0-9]{5}"

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply