Solved

Regular expression

Posted on 2006-11-30
1
180 Views
Last Modified: 2011-09-20
I have the following:

MatchCollection NewMatch = Regex.Matches(Str2LookIn, @"[/*\\*]([\(\)\#a-z0-9\._-]*)", RegexOptions.IgnoreCase);
                  if (NewMatch.Count > 0)
                  {
                        if (Str2LookIn.IndexOf(@"http://") == -1)
                              return NewMatch[NewMatch.Count - 1].Groups[0].Captures[0].ToString();
                        else
                        {
                              //MessageBox.Show(NewMatch[NewMatch.Count - 2].Groups[1].Captures[0].ToString());
                              return (NewMatch[NewMatch.Count - 2].Groups[1].Captures[0].ToString() +
                                    NewMatch[NewMatch.Count - 1].Groups[1].Captures[0].ToString());
                      }
                  }
                  else
                  {
                        NewMatch = Regex.Matches(Str2LookIn, @"^(about:(blank)?)?([\(\)_\-\.a-z0-9]*\.+[a-z]{4})(\#+([_\-\.a-z0-9]*))?", RegexOptions.IgnoreCase);
                        if (NewMatch.Count != 0)
                              return NewMatch[0].Groups[3].Captures[0].ToString();
                        else
                              return "";
                  }
            


I need       if (Str2LookIn.IndexOf(@"http://") == -1)
to execute if  the string is http://www.aircanada.com


<table class="CompanyInfo">
<tr>
<td align="center">
<p><a href="http://www.aircanada.com" target="_blank"><img src="../../images/Home/Logo_AirCandaACGHS-www.jpg"><br>
<span class="CompanyName">Air Canada ACGHS</span><br>http://www.aircanada.com</a></p>
</td>
</tr>
</table>


Something is wrong with that line of code can someone help me out.
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
CBeach1980 earned 500 total points
ID: 18048315
(Str2LookIn.IndexOf(@"http://") == -1) will only execute if "http://" is not in Str2LookIn.  To get it to execute when it is there you need (Str2LookIn.IndexOf(@"http://") != -1)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question