Regex pattern to allow all brackets and alphanumeric - angularjs

I'm looking for a regex pattern to accept alphanumeric plus some of the special characters - (, /'() {[])

ng-pattern="/^[a-zA-Z _\\\/.,ā€™'\-{[\]}]+$/"
Should allow only Alpha characters [a-zA-Z]
Allow certain special characters [_/.,'-{}[]]

Related

Regex inside split() method unintended side-effect [duplicate]

$.validator.addMethod('AZ09_', function (value) {
return /^[a-zA-Z0-9.-_]+$/.test(value);
}, 'Only letters, numbers, and _-. are allowed');
When I use somehting like test-123 it still triggers as if the hyphen is invalid. I tried \- and --
Escaping using \- should be fine, but you can also try putting it at the beginning or the end of the character class. This should work for you:
/^[a-zA-Z0-9._-]+$/
Escaping the hyphen using \- is the correct way.
I have verified that the expression /^[a-zA-Z0-9.\-_]+$/ does allow hyphens. You can also use the \w class to shorten it to /^[\w.\-]+$/.
(Putting the hyphen last in the expression actually causes it to not require escaping, as it then can't be part of a range, however you might still want to get into the habit of always escaping it.)
The \- maybe wasn't working because you passed the whole stuff from the server with a string. If that's the case, you should at first escape the \ so the server side program can handle it too.
In a server side string: \\-
On the client side: \-
In regex (covers): -
Or you can simply put at the and of the [] brackets.
Generally with hyphen (-) character in regex, its important to note the difference between escaping (\-) and not escaping (-) the hyphen because hyphen apart from being a character themselves are parsed to specify range in regex.
In the first case, with escaped hyphen (\-), regex will only match the hyphen as in example /^[+\-.]+$/
In the second case, not escaping for example /^[+-.]+$/ here since the hyphen is between plus and dot so it will match all characters with ASCII values between 43 (for plus) and 46 (for dot), so will include comma (ASCII value of 44) as a side-effect.
\- should work to escape the - in the character range. Can you quote what you tested when it didn't seem to? Because it seems to work: http://jsbin.com/odita3
A more generic way of matching hyphens is by using the character class for hyphens and dashes ("\p{Pd}" without quotes). If you are dealing with text from various cultures and sources, you might find that there are more types of hyphens out there, not just one character. You can add that inside the [] expression

What does the letter c do in Snowflake?

While using Snowflake, I saw the letter c within a WHERE clause
WHERE unnest_channel IN ('Referral - Merchant','Referral - Whitelabel')c
What does it do? (Some kind of casting?)
The default string is simply c, which specifies:
Case-sensitive matching.
Single-line mode.
No sub-match extraction, except for REGEXP_REPLACE, which always uses sub-match extraction.
POSIX wildcard character . does not match \n newline characters.
When specifying multiple parameters, the string is entered with no spaces or delimiters. For example, ims specifies case-insensitive matching in multi-line mode with POSIX wildcard matching.
If both c and i are included in the parameters string, the one that occurs last in the string dictates whether the function performs case-sensitive or case-insensitive matching. For example, ci specifies case-sensitive matching because the ā€œiā€ occurs last in the string.

RegEx for matching two letters with special boundaries

I want to make sure user input has:
Two letters at the start
And the support for any number of optional space characters following these two letters.
Additionally, if at least one space character is provided, optionally allow letters, digits or . characters after it.
Here's the expression I currently have:
[a-zA-Z][a-zA-Z] (?\\s+ (?a-zA-Z0-9.))
And here's my thinking:
[a-zA-Z][a-zA-Z] makes sure the input begins with at least two letters
(?\\s+ begins an optional statement. This optional statement must start with at least one space (I'm on windows which is why I have two slashes).
(?a-zA-Z0-9.)) finishes the optional statement. So, if at least one space is provided, at least one optional character, number or . can also be added.
For instance, ab, ab , ab .s, and ab .asd2 should all be valid inputs.
How do I solve this problem?
The problem with your attempt is that both (?\ and (?a are syntax errors. If you want to create an optional group, you need to write (...)?, not (?...).
(The other issue is that a-zA-Z0-9 in your regex matches literally because it's not part of a character class.)
Besides, \s (to match whitespace) does not exist in POSIX regex.
My suggestion:
^[a-zA-Z]{2}( +[a-zA-Z0-9.]*)?$
That is:
^ # beginning of string
[a-zA-Z]{2} # exactly two letters
(
\ + # one or more spaces
[a-zA-Z0-9.]* # zero or more of: letters, digits, or dot
)? # ... this group is optional
$ # end of string

ng-pattern for alphanumeric and all special symbol characters

In input, I need to allow alphanumeric and all special symbol character.
I am using the following pattern. Unfortunatelly, it is not working.
ng-pattern="/^[ A-Za-z0-9_#./#$=!%^)(]:*;?/\,}{'|<>[&+-]*$/"
You missed to escape all the characters that should be excaped with \. The following may work:
ng-pattern="/^[A-Za-z0-9_#.#$=!%^)(\]:\*;\?\/\,}{'\|<>\[&\+-]*$/"
Note that it could be simplified to:
ng-pattern="/^[A-z\d_#.#$=!%^)(\]:\*;\?\/\,}{'\|<>\[&\+-]*$/"
Test it on regex101

Can table name start with integer in Redshift

I have a customer trying to create a table name starting with a number followed by alphabet ( example: 1234-testtable ) and the redshift is throwing
ERROR: syntax error at or near "1234" Position:53
Can't we create a table name starting with number in Amazon Redshift ?
According to the Names and Identifiers documentation, you cannot start your identifier with a digit and it cannot contain a hyphen as only
ASCII letters, digits, underscore characters (_), or dollar signs ($) are valid characters. The complete set rules for Redshift is:
Contain only ASCII letters, digits, underscore characters (_), or dollar signs ($).
Begin with an alphabetic character or underscore character.
Subsequent characters may include letters, digits, underscores, or dollar signs.
Be between 1 and 127 characters in length, not including quotes for delimited identifiers.
Contain no quotation marks and no spaces. Not be a reserved SQL key word.
Thus you could elect for a name like testtable_1234 instead.

Resources