c# - Should i use regular expression in this situation? -
i have xml file containing expressions :-
1. aaaaaaa-1111 2. aaaaa-1111-aaa 3. aa11111-11111 4. aa111-111-111111
(aa static text) (aaaa-any alphabet only) hyphen (1111 - digit only)
i thinking should write regular expression these believe regex should right approach.
but xml file dynamic. user can remove or add different expressions in list. how can use regular expression here? there dynamic regular expression kind of thing. show me light here please.
update:- using these expressions validate user input. whatever user entering in box, should matched of these expressions list.
for example:-
if user enters
aaabc-4567-trr
, should validated coz matches 2nd expression in list
well,
what assume question that:
a
letter a
a
letter
1
number
that's way see aaabc-4567-trr
matches aaaaa-1111-aaa
is correct?
if correct, yes, use regular expressions. need translate your patterns regex patterns. assuming have new pattern:
aaa-aaa-111
to obtain regex recognize pattern, have translate pattern regex patterns. example:
string xmlpattern = "aaa-aaa-111" string regexpattern = xmlpattern.replace("a", "[a-za-z]").replace("1", @"\d");
edit:
should take in count other characters have special meanings in regular expressions, , translate/encode them properly. maybe classify them. example, these characters:
.
, $
, ^
can translated regex patterns encoding them \
before, become:
\.
, \$
, \^
, ...
if can specify format of validation patterns storing in xml files, little more, i'm writing answer kind of blind ;)
Comments
Post a Comment