Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    184

    [VB6] Espressioni regolari RegExp

    Non riesco a convalidare questa espressione regolare quando chiamo la funzione:
    Call TestRegExp("[A-N P-Z O-9]", "ABC")
    xchè l'ambiente mi restituisce il messaggio "Errore definito dall'applicazione o dall'oggetto"
    dove TestRegExp è così definita:

    Function TestRegExp(myPattern As String, myString As String)
    'Create objects.
    Dim objRegExp As RegExp
    Dim objMatch As Match
    Dim colMatches As MatchCollection
    Dim RetStr As String

    ' Create a regular expression object.
    Set objRegExp = New RegExp

    'Set the pattern by using the Pattern property.
    objRegExp.Pattern = myPattern

    ' Set Case Insensitivity.
    objRegExp.IgnoreCase = True

    'Set global applicability.
    objRegExp.Global = True

    'Test whether the String can be compared.
    If (objRegExp.Test(myString) = True) Then

    'Get the matches.
    Set colMatches = objRegExp.Execute(myString) ' Execute search.

    For Each objMatch In colMatches ' Iterate Matches collection.
    RetStr = RetStr & "Match found at position "
    RetStr = RetStr & objMatch.FirstIndex & ". Match Value is '"
    RetStr = RetStr & objMatch.value & "'." & vbCrLf
    Next
    Else
    RetStr = "String Matching Failed"
    End If
    TestRegExp = RetStr
    End Function

    Mi chiedo...è sbagliata l'espressione "[A-N P-Z O-9]" ?...c'è un altro modo per poterla scrivere?
    Se inserisco questa epressione invece [A-Z]{6,6}[A-Z 2-9]([A-Z 0-9]{3,3}){0,1} non ho alcun problema..

    Thanks

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Non ho fatto prove ma nella linea

    "[A-N P-Z O-9]"

    mi sembra che O sia la lettera maiuscola e non lo zero ! Dovrebbe essere

    "[A-N P-Z 0-9]"

    (nota la differenza)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.