|
-
April 10th, 2003, 11:12 AM
#1
Regular expression
Look at this code...
==============================================
string strClaim = "BER";
Regex objNaturalPattern = new Regex("[Bb][Ee][Rr]|[Tt][Ww][Oo]|[Ss][Tt][Oo]");
objNaturalPattern.IsMatch(strClaim);
==============================================
ok the return value to "objNaturalPattern.IsMatch(strClaim);" will be true as it matches [Bb][Ee][Rr]. Now what I might want to do and it needn't only apply to this example is know which Regular expression ([Bb][Ee][Rr]|[Tt][Ww][Oo]|[Ss][Tt][Oo])the string matched.
Is there any possible way to get some kinda of return value to say which one was matched?
as in a string matching [Bb][Ee][Rr] would return 0
as in a string matching [Tt][Ww][Oo] would return 1
as in a string matching [Ss][Tt][Oo] would return 2
no match could return -1
Is this posible? Is there a method that I have over looked?
elp!
-
April 10th, 2003, 11:17 AM
#2
no , I don't think so that's possible.
you could check with making 3 Regex's and matching them individually.
first match with this original one and if it matches then try fetching with sub-Regex ones.
so that you would know where it matched or failed.
Paresh
- Software Architect
-
April 10th, 2003, 11:21 AM
#3
Yeah I know I could do that but what happens if I have....
m_sCONNACHT = "[G][A][L][W][A][Y]|[M][A][Y][O]|[L][E][I][T][R][I][M]|[R][O][S][C][O][M][M][O][N]|[S][L][I][G][O]";
m_sMUNSTER = "[C][L][A][R][E]|[C][O][R][K]|[K][E][R][R][Y]|[L][I][M][E][R][I][C][K]|[T][I][P][P][E][R][A][R][Y]|[W][A][T][E][R][F][O][R][D]";
m_sLEINSTER = "[C][A][R][L][O][W]|[D][U][B][L][I][N]|[K][I][L][D][A][R][E]|[K][I][L][K][E][N][N][Y]|[L][A][O][I][S]|[L][O][N][G][F][O][R][D]|[L][O][U][T][H]|[M][E][A][T][H]|[O][F][F][A][L][Y]|[W][E][S][T][M][E][A][T][H]|[W][E][X][F][O][R][D]|[W][I][C][K][L][O][W]";
m_sULSTERROI = "[C][A][V][A][N]|[D][O][N][E][G][A][L]|[M][O][N][A][G][H][A][N]";
m_sULSTERNI = "[A][N][T][R][I][M]|[A][R][M][A][G][H]|[D][O][W][N|F][E][R][M][A][N][A][G][H]|[L][O][N][D][O][N][D][E][R][R][Y]|[T][Y][R][O][N][E]";
and this is a small snipet of what I'm matching and I plan to expand it!! It would take for ever to right all the if statements for that!
-
April 10th, 2003, 11:25 AM
#4
I don't understand why are you giving all the characters in your program. what is the sample string and what you are looking in it. perhaps it might happen that you might come up with some compact string.
Paresh
- Software Architect
-
April 10th, 2003, 11:31 AM
#5
I am writing a program that will check to see if a address strings is correct and if possible repair fix them. Its for Ireland and the address is broken up into 4 fields. ADR1, ADR2, TOWN and REGION. It will be used to check to see if some address in our datbase are correct. there are 3/4 million addresses in our dirty database. bit of a nightmare
Last edited by zoltan_ie; April 10th, 2003 at 11:33 AM.
-
April 10th, 2003, 11:33 AM
#6
so you can always check with , (comma) and . something like that and break up strings. FYI then analyze it again. right. or take out digits from the ADD1.
right. just like USA address.
Paresh
- Software Architect
-
April 10th, 2003, 04:05 PM
#7
check Groups[].value also...
Paresh
- Software Architect
-
April 24th, 2003, 05:27 AM
#8
string sAbbreviatedWord = "STO";
string CO = "((?<first>BER)|(?<second>TWO)|(?<third>STO))";
Regex regexpCO = new Regex(CO);
Match match = regexpCO.Match(sAbbreviatedWord);
GroupCollection matchGroup = match.Groups;
if(matchGroup["first"].Value != "")
return "BER";
if(matchGroup["second"].Value != "")
return "TWO";
if(matchGroup["third"].Value != "")
return "STO";
Is there any quicker way of checking which group was matched? instead of checking each one?
I know it seems pointless to use the techique I am using for such a small reg exp. I'm just using a small one as the ones I will be using are too big to post up.
ps. Thanks pareshgh you seem to always answer my posts. Just so you know it doesn't go unnoticed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|