webForumDet fria alternativet

regexp

3 svar · 230 visningar · startad av Frexuz

FrexuzMedlem sedan maj 2003138 inlägg
#1

vill kolla igenom en sträng om den innehåller 2 eller fler siffror irad och replace'a dom med '' (inget alltså)

och sedan få in den i denna koden efter alla mina andra replace

<body bgcolor="#333333" text="#FFFFFF">
<%
Function ProperCase(Value)
    ProperCase = UCase(Left(Value, 1)) & LCase(Mid(Value, 2))
End Function

Dim countOk, countChanged
countOk = + 0
countChanged = 0

Sub ShowFiles(ByRef objFS, ByRef lngFiles, ByRef lngFolders, ByRef lngSize, ByVal strPath)
   ' lokala variabler
   Dim objThisFolder, objFile, objFolder, orgName, tmpName, strName, arrName
   
      ' skapa ett objekt för mappen vi är i
   Set objThisFolder = objFS.GetFolder(strPath)
   ' loopa igenom alla mappar i mappen
   For each objFolder in objThisFolder.SubFolders
      ' visa allt i en undermapp
      Call ShowFiles(objFS, lngFiles, lngFolders, lngSize, strPath & "\" & objFolder.Name)
   Next
   ' loopa igenom alla filer i mappen
   For each objFile in objThisFolder.Files
	  		orgName = objFile.Name
			strName = objFile.Name
			tmpName = "tempMp3Name.mp3"

			strName = Replace(strName, "rmx", "Remix", 1, -1, vbTextCompare)
			strName = Replace(strName, "remix", "Remix")
			strName = Replace(strName, "ft.", "feat.")
			strName = Replace(strName, "featuring", "feat.")
			strName = Replace(strName, "featuring.", "feat.")
			strName = Replace(strName, " And ", "&")
			strName = Replace(strName, " and ", "&")
			strName = Replace(strName, "_", " ")
			strName = Replace(strName, " - ", "-")
			strName = Replace(strName, "-", " - ")
			arrName = Split(strName)
			
			For i = 0 To UBound(arrName)
				arrName(i) = ProperCase(arrName(i))
			Next
			
			strName = Join(arrName)
	
			If orgName = strName Then
				countOk = countOk + 1
			Else
				countChanged = countChanged + 1
				objFile.Name = tmpName
				objFile.Name = strName
				Response.Write "<font face=""verdana"" size=""1"" color=""#EEEEEE"">" & objThisFolder & "\" & orgName & ""
				Response.Write "<font color=""#FF0000""> -> </font><font color=""#EEEEEE"">" & strName & "</font><br>" & vbCrLf
			End If

   Next
   
End Sub

Dim objFS

Set objFS=Server.CreateObject("Scripting.FileSystemObject")
Call ShowFiles(objFS, lngFiles, lngFolders, lngSize, "c:\Mp3")
Set objFS = Nothing

response.write "<font face=""verdana"" size=""1"" color=""#EEEEEE""><b>Done</b></font>"
%>

(jag antar att regexp är det bästa sättet?)

Jesper TMedlem sedan nov. 20017 144 inlägg
#2

Detta kanske är ett pattern du kan använda: \d{3,}

Skall träffa nummeriska tecken som är fler än "två i rad"

FrexuzMedlem sedan maj 2003138 inlägg
#3

själva pattern är nog inte det svåra för mig, utan vad jag ska göra med resultatet typ

Engine^Medlem sedan dec. 20003 887 inlägg
#4

Du stoppar in följande efter dina replace kanske kan fungera. Det borde stryka allt med mer än en siffra i rad.

Set objRX = New RegEx

objRX.Global = True
objRX.Pattern = "\d{2,}"

strName = objRX.Replace(strName, "")
135 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
132 ms — hämta tråd, inlägg och bilagor (db)