WPF Regex special character '&' incorrect syntax - regex

In my WPF application I want to validate email with this conditions.
The local part can be up to 64 characters in length and consist of any combination of alphabetic characters, digits, or any of the following special characters: ! # $ % & ‘ * + – / = ? ^ _ ` . { | } ~.
My Regex is
[a-zA-Z0-9!#$%'*+–=?^_`.{|}~/&]{1,64}#[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}
But when i use '&' character it shows the following error
Expected the following token: ";".

I have found my solution.
I had to use &
and
My final Regex is
[^.][a-zA-Z0-9!#$%'*+=?^_`.{|}~-/&]{1,64}#[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}

Related

Regex to evaluate phone number in Pentaho [duplicate]

I wanted to remove the special characters like ! # # $ % ^ * _ = + | \ } { [ ] : ; < > ? / in a string field.
I used the "Replace in String" step and enabled the use RegEx. However, I do not know the right syntax that I will put in "Search" to remove all these characters from the string. If I only put one character in the "Search" it was removed from the string. How can I remove all of these??
This is the picture of how I did it:
As per documentation, the regex flavor is Java. You may use
\p{Punct}
See the Java regex syntax reference:
\p{Punct} Punctuation: One of !"#$%&'()*+,-./:;<=>?#[]^_`{|}~

Regular expression not working with \ and ]

I have a regex for validating a password which has to be at least 8 chars and must contain letter(upper and lower case) number and a special character from set ^ $ * . [ ] { } ( ) ? - " ! # # % & / \ , > < ' : ; | _ ~ ` .
I face 2 problems, after adding the / to the reg exp its not recognized (other characters are still working OK. If I add the /] as well the expression no longer works (everything is invalid though the pattern seems to be ok in the browser debug mode).
The regex string
static get PASSWORD_VALIDATION_REGEX(): string {
return '(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])' + // contains lowercase number uppercase
'(?=.*[\-~\$#!%#<>\|\`\\\/\[;:=\+\{\}\.\(\)*^\?&\"\,\'])' + // special
'.{8,}'; // more than allowed char
}
I used the regexp as a form validator and as a match in function
password: ['', {validators: [Validators.required,
Validators.pattern(StringUtils.PASSWORD_VALIDATION_REGEX)
],
updateOn: 'change'
}
]
//....
value.match(StringUtils.PASSWORD_VALIDATION_REGEX)
Tried to use only (?=.*[\\]) for the special chars list, in that case I've received a console error
Invalid regular expression: /^(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])(?=.*[\]).{8,}$/: Unterminated character class
For '(?=.*[\]])' no console error but the following error is present in the form validation 'pattern'
actualValue: "AsasassasaX000[[][]"
requiredPattern: "^(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])(?=.*[]]).{8,}$"
The same value and pattern fails on https://regex101.com/
Thanks for your help / suggestions in advance!
You have overescaped your pattern and failed to escape the ] char correctly. In JavaScript regex, ] inside a character class must be escaped.
If you are confused with how to define escapes inside a string literal (and it is rather confusing indeed), you should use a regex literal. One thing to remember about the regex use with Validators.pattern is that the string pattern is anchored by the Angular framework by enclosing the whole pattern with ^ and $, so these anchors must be present when you define the pattern as a regex literal.
Use
static get PASSWORD_VALIDATION_REGEX(): string {
return /^(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])(?=.*[-~$#!%#<>|`\\\/[\];:=+{}.()*^?&",']).{8,}$/;
}
Note the \] that matches a ] char and \\ to match \ inside [...].

Remove special characters using Pentaho - Replace in String

I wanted to remove the special characters like ! # # $ % ^ * _ = + | \ } { [ ] : ; < > ? / in a string field.
I used the "Replace in String" step and enabled the use RegEx. However, I do not know the right syntax that I will put in "Search" to remove all these characters from the string. If I only put one character in the "Search" it was removed from the string. How can I remove all of these??
This is the picture of how I did it:
As per documentation, the regex flavor is Java. You may use
\p{Punct}
See the Java regex syntax reference:
\p{Punct} Punctuation: One of !"#$%&'()*+,-./:;<=>?#[]^_`{|}~

Using regular expression to strip out every character that's not in a list

I want to strip out every character that isn't in a list of valid characters.
In this example, I want to strip out everything that's either: (a) not alphanumeric, or (b) is the e accent grave character:
Line = rereplace(Line,'[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' + Chr(233) + ']','','all')
I think , I just need a 'not' symbol or something .
You can use shortcuts for most of that:
Line = rereplace(Line,'[^A-Za-z0-9' + Chr(233) + ']','','all')
The ^ inside the bracket means 'not these characters'

Powershell regex are too annoying

I have the following URLs
http://servername:12345/sites/MYSITE1/SUBSITE1
http://servername:543/sites/MYSITE2/SUBSITE1/SUBSITE2
I would like to delete everything before and including /sites/ to give the following output
MYSITE1\SUBSITE1
MYSITE2\SUBSITE1\SUBSITE2
I have tried -replace "*/sites/","" but his doesn't give me the required result.
.* means any number of character. So it will remove all letters before the sites. Some characters ". ^ $ * + ? { [ ] \ | ( ) “ has special meaning in regex. So we need to mask it to use literally using “\”. Example “/” for the “/”. Try this.
"http://servername:12345/sites/MYSITE1/SUBSITE1" -replace ".*sites\/",""