Добрый день. Помогите, пожалуйста, с регулярным выражением. Необходимо все вхождения типа 1. asdf. 2. xv cb-1. 3. uio №1 uio. преобразовать в список: 1. asdf. 2. xv cb-1. 3. uio №1 uio.
Написал такое, но оно не работает, как надоть:
Код
Public Function NormPhrase(ByVal s As String) As String
On Error Resume Next
Dim re As Object, mtchs As Object, i As Integer, p As String
Set re = CreateObject("VBScript.RegExp"): re.Global = True: re.MultiLine = True
re.Pattern = "(.+\.\s)([0-9]{1,2}\.\s.*)"
Do While s Like "* *"
s = Replace(s, " ", " ")
Loop
s = Trim(Replace(Replace(s, " .", "."), " ,", ","))
s = UCase(Left(s, 1)) & Right(s, Len(s) - 1) & IIf(Right(s, 1) = ".", "", ".")
Debug.Print s
Set mtchs = re.Execute(s)
For i = 0 To mtchs.Count - 1
p = p & mtchs.Item(i).Submatches.Item(0) & vbLf & mtchs.Item(i).Submatches.Item(1)
Next
NormPhrase = p
End Function
Sub tstNormPhrase()
Debug.Print NormPhrase("1. asdf. 2. xv cb-1. 3. uio №1 uio.")
End Sub
Public Function NormPhrase(ByVal s As String) As String
On Error Resume Next
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.MultiLine = True
re.Pattern = "(\.)+(\s)(\d+\.\s+)"
s = re.Replace(s, "$1" & vbLf & "$3")
NormPhrase = s
End Function
Sub tstNormPhrase()
Debug.Print NormPhrase("1. asdf. 2. xv cb-1. 3. uio №1 uio.")
End Sub