Solved

Regular expression

Posted on 2006-11-30
1
167 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now