Avatar billede loukas Mester
20. marts 2003 - 09:18 Der er 6 kommentarer og
1 løsning

RegEexp link

Jeg kan med functionen finde links,
men jeg ville gerne have linket skrevet.
F.eks: http://domænenavn/fil.asp
Hvordan gør jeg ??

sOuts = RegExpTest("a href", sOuts)

Function RegExpTest(patrn, strng)
  Dim regEx, Match, Matches  ' Create variable.
  Set regEx = New RegExp  ' Create regular expression.
  regEx.Pattern = patrn  ' Set pattern.
  regEx.IgnoreCase = True  ' Set case insensitivity.
  regEx.Global = True  ' Set global applicability.
  Set Matches = regEx.Execute(strng)  ' Execute search.
  For Each Match in Matches  ' Iterate Matches collection.
      RetStr = RetStr & "Match " & I & " found at position "
      RetStr = RetStr & Match.FirstIndex & ". Match Value is "'
      RetStr = RetStr & Match.Value & "'.<br>" & vbCRLF
  Next
  RegExpTest = RetStr
 
End Function
Avatar billede oasen Nybegynder
20. marts 2003 - 09:24 #1
RetStr = RetStr & "Match " & I & " found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is "'
RetStr = RetStr & Replace(Match.Value, "<a href='" & Match.Value & "'>" & Match.Value & "</a>)'.<br>" & vbCRLF
Avatar billede oasen Nybegynder
20. marts 2003 - 09:26 #2
Du får den lige igen:

RetStr = RetStr & "Match " & I & " found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is "'
RetStr = RetStr & Replace(Match.Value, "<a href='" & Match.Value & "'>" & Match.Value & "</a>") & "'.<br>" & vbCRLF
Avatar billede loukas Mester
20. marts 2003 - 09:36 #3
Jeg får en fejl :-(
er det når jeg kalder den ??

Fejlen:
Der opstod en Microsoft VBScript-kørselsfejl (0x800A01C2)
Antallet af argumenter er forkert eller egenskabstildelingen er ugyldig: 'Replace'


Koden:
sOuts = RegExpTest("a href", sOuts)

Function RegExpTest(patrn, strng)
  Dim regEx, Match, Matches  ' Create variable.
  Set regEx = New RegExp  ' Create regular expression.
  regEx.Pattern = patrn  ' Set pattern.
  regEx.IgnoreCase = True  ' Set case insensitivity.
  regEx.Global = True  ' Set global applicability.
  Set Matches = regEx.Execute(strng)  ' Execute search.
  For Each Match in Matches  ' Iterate Matches collection.
RetStr = RetStr & "Match " & I & " found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is "'
RetStr = RetStr & Replace(Match.Value, "<a href='" & Match.Value & "'>" & Match.Value & "</a>") & "'.<br>" & vbCRLF
  Next
  RegExpTest = RetStr
 
End Function
Avatar billede loukas Mester
20. marts 2003 - 09:40 #4
og vil match.value ikke blive til 'a href' ?!?!?!
Avatar billede loukas Mester
20. marts 2003 - 11:25 #5
jeg har fundet ud af det :-)

Function RegExpTest(strng)
  Dim regEx, Match, Matches  ' Create variable.
  Set regEx = New RegExp  ' Create regular expression.
  regEx.Pattern = "(\bhttp\:\/\/)?(\bw{3}\.\S+\.[a-z][a-z]+\b)(\/\S+\b)?(\?\S+\b)?"
  regEx.IgnoreCase = True  ' Set case insensitivity.
  regEx.Global = True  ' Set global applicability.
  Set Matches = regEx.Execute(strng)  ' Execute search.
  For Each Match in Matches  ' Iterate Matches collection.
RetStr = RetStr & "Match " & I & " found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is "'
RetStr = Match.Value & vbCRLF
  Next
  RegExpTest = RetStr
 
End Function
Avatar billede loukas Mester
20. marts 2003 - 11:25 #6
-
Avatar billede oasen Nybegynder
20. marts 2003 - 12:17 #7
Det var mig, der havde lavede en bommert. Det skal selvfølgelig være:

RetStr = RetStr & "Match " & I & " found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is "'
RetStr = RetStr & Replace(RetStr, Match.Value, "<a href='" & Match.Value & "'>" & Match.Value & "</a>") & "'.<br>" & vbCRLF
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester