Reputation: 245
Can someone tell me the error in Regex for below mentioned things:
Regex: @"^(tcm:\d+-\d+)"
Input String: tcm:12-123a6
Problem: \d should only match numerals as per my knowledge. Input string has 'a' in it. Still it matches the input string.
Regex: @"^[a-zA-Z0-9,&\s-]*$"
Input String: Transportation, Tourism & Travel
which I am reading
from Query String and comes as
Transportation%252c%2bTravel%2b%2526%2bTourism
Problem: I think I have taken all the characters of input into Regex. Still it does not match.
Regex: @"^[a-zA-Z0-9=]*$"
Input String: U2VuaW9yIFBhcnRuZXIgJiBNYW5hZ2luZyB&&&EaXJlY3Rvcg==
Problem: Even with '&' in input, why is it matching?
Upvotes: 2
Views: 214
Reputation: 12807
@"^(tcm:\d+-\d+)" will match tcm:12-123 from your string, you need to put $ in the end of your regex to match whole string.
@"^(tcm:\d+-\d+)$"
If ':' belongs to the string, then you need to add it to your list.
@"^[a-zA-Z0-9,&\s-:]*$"
Upvotes: 1