I've created the following regex:
(^[%a-zA-Z][\w\-.]+)( [\w\-.]+|[\w\-.]+)([%A-Za-z.]$)
strings that should be allowed e.g.
test (working)
test test (working)
%test (working)
test% (working)
%test% (working)
% (not working)
I tried the following to make % only work:
(%|(^[%a-zA-Z][\w\-.]+)( [\w\-.]+|[\w\-.]+)([%A-Za-z.]$))
the defined pattern works fine with https://www.debuggex.com, but fails in my application, where the model looks like:
[Display(Name = "Publisher")]
[RegularExpression(@"(%|(^[%a-zA-Z][\w\-.]+)( [\w\-.]+|[\w\-.]+)([%A-Za-z.]$))", ErrorMessage = "Invalid Expression!")]
public string SoftwarePublisher { get; set; }
any advice would be helpful. thanks in advance
This pattern should be bit better than yours give it a try as it works for me:
PATTERN
(^|%)((\w+\s?)+)([^\s]$|%)|%
INPUT
case 1: test
case 2: test
case 3: %test
case 4: test%
case 5: %test%
case 6: %
OUTPUT
case 1: matches
case 2: matches
case 3: matches
case 4: matches
case 5: matches
case 6: matches
Hope it will work for you or at least give you some hint. If you will test it on some website use all strings separately as I'm using ^
and $
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments