gera_serg
Advanced Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Не задумывался о размере. Я исползую для обработки содержимого клипборда для "чистки" загнанного туда html созданного MSWord (у него лишних тегов - дофига) Добавлено: Обрати внимания у MS существуют три метода работы с RegExp Test Method See Also Execute Method | Replace Method Applies To: RegExp Object Requirements Version 5 Executes a regular expression search against a specified string and returns a Boolean value that indicates if a pattern match was found. object.Test(string) Arguments object Required. Always the name of a RegExp object. string Required. The text string upon which the regular expression is executed. Remarks The actual pattern for the regular expression search is set using the Pattern property of the RegExp object. The RegExp.Global property has no effect on the Test method. The Test method returns True if a pattern match is found; False if no match is found. The following code illustrates the use of the Test method. Function RegExpTest(patrn, strng) Dim regEx, retVal ' Create variable. Set regEx = New RegExp ' Create regular expression. regEx.Pattern = patrn ' Set pattern. regEx.IgnoreCase = False ' Set case sensitivity. retVal = regEx.Test(strng) ' Execute the search test. If retVal Then RegExpTest = "One or more matches were found." Else RegExpTest = "No match was found." End If End Function MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4")) Добавлено: Executes a regular expression search against a specified string. object.Execute(string) Arguments object Required. Always the name of a RegExp object. string Required. The text string upon which the regular expression is executed. Remarks The actual pattern for the regular expression search is set using the Pattern property of the RegExp object. The Execute method returns a Matches collection containing a Match object for each match found in string. Execute returns an empty Matches collection if no match is found. The following code illustrates the use of the Execute method. Function RegExpTest(patrn, strng) Dim regEx, Match, Matches ' Create variable. Set regEx = New RegExp ' Create a 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 found at position " RetStr = RetStr & Match.FirstIndex & ". Match Value is '" RetStr = RetStr & Match.Value & "'." & vbCRLF Next RegExpTest = RetStr End Function MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4")) Добавлено: Replace Method See Also Execute Method | Test Method Applies To: RegExp Object Requirements Version 5 Replaces text found in a regular expression search. object.Replace(string1, string2) Arguments object Required. Always the name of a RegExp object. string1 Required. String1 is the text string in which the text replacement is to occur. string2 Required. String2 is the replacement text string. Remarks The actual pattern for the text being replaced is set using the Pattern property of the RegExp object. The Replace method returns a copy of string1 with the text of RegExp.Pattern replaced with string2. If no match is found, a copy of string1 is returned unchanged. The following code illustrates use of the Replace method. Function ReplaceTest(patrn, replStr) Dim regEx, str1 ' Create variables. str1 = "The quick brown fox jumped over the lazy dog." Set regEx = New RegExp ' Create regular expression. regEx.Pattern = patrn ' Set pattern. regEx.IgnoreCase = True ' Make case insensitive. ReplaceTest = regEx.Replace(str1, replStr) ' Make replacement. End Function MsgBox(ReplaceTest("fox", "cat")) ' Replace 'fox' with 'cat'. In addition, the Replace method can replace subexpressions in the pattern. The following call to the function shown in the previous example swaps each pair of words in the original string: MsgBox(ReplaceTest("(\S+)(\s+)(\S+)", "$3$2$1")) ' Swap pairs of words. Добавлено: В другом скрипте для обработки (поиска и замены) текстовых файлов я заметил что гораздо быстрее обрабатывается полный файл в буфере, чем если брать файл построчно обрабатывать и записывать построчно на диск... | Всего записей: 788 | Зарегистр. 24-07-2002 | Отправлено: 16:35 16-06-2005 | Исправлено: gera_serg, 17:09 16-06-2005 |
|