Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Regular expressions

  Asked By: Frankie    Date: Jun 23    Category: Asp.net    Views: 927
  

i'm trying to get a particular part of an HMTL-source

i've the whole HTML source-code stored in a variable myHTML
i've a searchword stored in a variable myTitle

now i want to get all parts of html that match with myTitle and so get an url:
But my regex doesn't work as well
Someone sees my faults?


CODE SNIPPET
*******************


Dim myExpression As String = "<a .+? (href=['""]) [^>]*? \> *mytitle* <\a>"
Dim regex As New Regex(myExpression, RegexOptions.IgnoreCase)
Dim mt As Match
Dim gp As Group

mt = regex.Match(myHTML)
For Each gp In mt.Groups
TextBox1.Text += gp.Value & "....."
Next

WHAT DO I WANT:
***********************

for example: this is a part of myHTML

- <a href="s/sexandlucia.php">Sex and Lucia</a> (2002)<br>
- <a href="s/sexiscomedy.php">Sex is Comedy</a> (2003)<br>
- <a href="../movies/s/sexybeast.php">Sexy Beast</a> (2001)<br>
- <a href="../movies/s/shadowglories.php">Shadow Glories</a>
(2001)<br>
- <a href="s/shadowofvampire.php">Shadow of the Vampire</a>
(2000)<br>
- <a href="s/shaft.php">Shaft</a> (2000)<br>
- <a href="../movies/s/shallowhal.php">Shallow Hal</a> (2001)<br>
- <a href="s/shaolinsoccer.php">Shaolin Soccer</a> (2003)<br>
- <a href="s/shanghaighetto.php">Shanghai Ghetto</a> (2002)<br>
- <a href="s/shanghaiknights.php">Shanghai Knights</a> (2003)<br>
- <a href="s/shapeofthings.php">The Shape of Things</a> (2003)<br>
- <a href="s/sharkslayer.php">Sharkslayer</a> (2004)<br>
- <a href="s/shatteredglass.php">Shattered Glass</a> (2003)<br>
- <a href="../movies/s/shippingnews.php">The Shipping News</a>
(2001)<br>
- <a href="../movies/s/shotatglory.php">A Shot at Glory</a>
(2001)<br>
- <a href="../movies/s/showtime.php">Showtime</a> (2002)<br>
- <a href="../movies/s/shrek.php">Shrek</a> (2001)<br>
- <a href="../movies/s/shrek2.php">Shrek2</a> (2001)<br>

i want to get the link of: shrek - <a href="../movies/s/shrek.php">Shrek</a>
(2001)<br>
So myTitle is in that case = Shrek

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Adalwin Fischer     Answered On: Jun 23

Is there any benefit to using Regex (regular expressions) to do replaces or
splits over the String methods or is it just preference?

 
Answer #2    Answered By: Skye Hughes     Answered On: Jun 23

I think with string  methods you can replace or split using a char and
with regex you can do splits and replaces with strings.

 
Answer #3    Answered By: Funsani Chalthoum     Answered On: Jun 23

So what I am trying to do is create
SqlDateTime object to search SQL server with for a date range return. I
have 4 fields being passed in:

Start Date; //MM/DD/YYYY
Start Time; //HH:MM [a.m. or p.m.]
End Date; //MM/DD/YYYY
End Time; //HH:MM [a.m. or p.m.]

I was going to use the regular  expression to slit these up and create new
SqlDateTime objects once I converted them to Integers. Then I saw you can
use the SqlDateTime.Parse(String s) to do this. I don't know however what
format the two strings need to be in. I looked on the Microsoft site and
they don't list a format. Does anyone know what format I have to
concatenate the Date and Time strings into to pass this in? Do I have to
covert the time to military time?

 
Answer #4    Answered By: Randall Franklin     Answered On: Jun 23

From a bit of experimentation, it seems to need the date & time in a format
like 'MM/DD/YYYY HH:MM:SS' or 'MM/DD/YYYY HH:MM:SS am/pm', & will happily
convert '01:10:25 pm' to 13:10:25

 
Didn't find what you were looking for? Find more on Regular expressions Or get search suggestion and latest updates.




Tagged: