Что нового

Поиск заголовка окна по регулярному выражению

lightforever

Новичок
Сообщения
37
Репутация
2
Хочу произвести поиск окна по рег выражению. В руководстве написано, что это можно сделать Но я пытаюсь писать например так: $a=WinList("Te[se]*") - ничего не выдаёт, хотя такое окно есть( я так понимаю он понимает это как строку. Подумывал о том, что надо передать объект регулярного выражения, но String Reg Expression не подошёл, т.к. он требует текст, в котором будим делать поиск по шаблону.
 

kaster

Мой Аватар, он лучший самый
Команда форума
Глобальный модератор
Сообщения
4,020
Репутация
626
Re: Поиск по регулярному выражению

Попробуй так
Код:
$a=WinList("[REGEXPTITLE:Te[se]*]")
 

killbond

Осваивающий
Сообщения
96
Репутация
32
String Reg Expression не подошёл, т.к. он требует текст, в котором будим делать поиск по шаблону.
А почему бы в качестве требуемого текста этой функции не предоставить каждое имя окна? Вот:
Код:
#include <Array.au3>

$sString = "Выражение"

_ArrayDisplay (_GetRegExpWnd ($sString))

Func _GetRegExpWnd ($sExp)
	Local $avOrgnlWnds = WinList ()
	dim $avScndWnds [1] [2]
	For $iWndCntr = 1 to $avOrgnlWnds [0] [0]
		if StringRegExp ( $avOrgnlWnds [$iWndCntr] [0], $sExp, 0) then
			ReDim $avScndWnds [UBound($avScndWnds)+1] [2]
			$avScndWnds [UBound($avScndWnds)-1] [0] = $avOrgnlWnds [$iWndCntr] [0]
			$avScndWnds [UBound($avScndWnds)-1] [1] = $avOrgnlWnds [$iWndCntr] [1]
		EndIf
	Next
	$avScndWnds [0] [0] = UBound($avScndWnds)-1
	if Not @error then 
		Return $avScndWnds
	Else 
		Return 0
	EndIf
EndFunc


В этом случае синтаксис выражения будет таким же, как и у StringRegExp
 
Автор
L

lightforever

Новичок
Сообщения
37
Репутация
2
Для того и придумали регулярные выражения чтобы Такая запись
killbond сказал(а):
String Reg Expression не подошёл, т.к. он требует текст, в котором будим делать поиск по шаблону.
А почему бы в качестве требуемого текста этой функции не предоставить каждое имя окна? Вот:
Код:
#include <Array.au3>

$sString = "Выражение"

_ArrayDisplay (_GetRegExpWnd ($sString))

Func _GetRegExpWnd ($sExp)
	Local $avOrgnlWnds = WinList ()
	dim $avScndWnds [1] [2]
	For $iWndCntr = 1 to $avOrgnlWnds [0] [0]
		if StringRegExp ( $avOrgnlWnds [$iWndCntr] [0], $sExp, 0) then
			ReDim $avScndWnds [UBound($avScndWnds)+1] [2]
			$avScndWnds [UBound($avScndWnds)-1] [0] = $avOrgnlWnds [$iWndCntr] [0]
			$avScndWnds [UBound($avScndWnds)-1] [1] = $avOrgnlWnds [$iWndCntr] [1]
		EndIf
	Next
	$avScndWnds [0] [0] = UBound($avScndWnds)-1
	if Not @error then 
		Return $avScndWnds
	Else 
		Return 0
	EndIf
EndFunc


В этом случае синтаксис выражения будет таким же, как и у StringRegExp

Свелась к такой: $a=WinList("[REGEXPTITLE:Te[se]*]") :smile: :smile:
 

killbond

Осваивающий
Сообщения
96
Репутация
32
Свелась к такой: $a=WinList("[REGEXPTITLE:Te[se]*]")
Зато у StringRegExp возможности регулярных выражений шире! :laugh:

[ ... ] Match any character in the set. e.g. [aeiou] matches any lower-case vowel. A contiguous set can be defined using a dash between the starting and ending characters. e.g. [a-z] matches any lower case character. To include a dash (-) in a set, use it as the first or last character of the set. To include a closing bracket in a set, use it as the first character of the set. e.g. [][] will match either [ or ]. Note that special characters do not retain their special meanings inside a set, with the exception of \\, \^, \-,\[ and \] match the escaped character inside a set.
[^ ... ] Match any character not in the set. e.g. [^0-9] matches any non-digit. To include a caret (^) in a set, put it after the beginning of the set or escape it (\^).
[:class:] Match a character in the given class of characters. Valid classes are: alpha (any alphabetic character), alnum (any alphanumeric character), lower (any lower-case letter), upper (any upper-case letter), digit (any decimal digit 0-9), :rofl:igit (any hexadecimal digit, 0-9, A-F, a-f), space (any whitespace character), blank (only a space or tab), print (any printable character), graph (any printable character except spaces), cntrl (any control character [ascii 127 or <32]) or punct (any punctuation character). So [0-9] is equivalent to [[:digit:]].
[^:class:] Match any character not in the class, but only if the first character.
( ... ) Group. The elements in the group are treated in order and can be repeated together. e.g. (ab)+ will match "ab" or "abab", but not "aba". A group will also store the text matched for use in back-references and in the array returned by the function, depending on flag value.
(?i) Case-insensitivity flag. This does not operate as a group. It tells the regular expression engine to do case-insensitive matching from that point on.
(?-i) (default) Case-sensitivity flag. This does not operate as a group. It tells the regular expression engine to do case-sensitive matching from that point on.
(?: ... ) Non-capturing group. Behaves just like a normal group, but does not record the matching characters in the array nor can the matched text be used for back-referencing.
(?i: ... ) Case-insensitive non-capturing group. Behaves just like a non-capturing group, but performs case-insensitive matches within the group.
(?-i: ... ) Case-sensitive non-capturing group. Behaves just like a non-capturing group, but performs case-sensitive matches within the group.
(?m) ^ and $ match newlines within data.
(?s) . matches anything including newline. (by default "." don't match newline)
(?x) Ignore whitespace and # comments.
(?U) Invert greediness of quantifiers.
. Match any single character (except newline).
| Or. The expression on one side or the other can be matched.
\ Escape a special character (have it match the actual character) or introduce a special character type (see below).
\\ Match an actual backslash (\).
\a Alarm, that is, the BEL character (chr(7)).
\A Match only at beginning of string.
\b Matches at a word boundary.
\B Matches when not at a word boundary.
\c Match a control character, based on the next character. For example, \cM matches ctrl-M.
\d Match any digit (0-9).
\D Match any non-digit.
\e Match an escape character (chr(27)).
\E end case modification.
\f Match an formfeed character (chr(12)).
\h any horizontal whitespace character.
\H any character that is not a horizontal whitespace character.
\n Match a linefeed (@LF, chr(10)).
\Q quote (disable) pattern metacharacters till \E.
\r Match a carriage return (@CR, chr(13)).
\s Match any whitespace character: Chr(9) through Chr(13) which are Horizontal Tab, Line Feed, Vertical Tab, Form Feed, and Carriage Return, and the standard space ( Chr(32) ).
\S Match any non-whitespace character.
\t Match a tab character (chr(9)).
\v any vertical whitespace character.
\V any character that is not a vertical whitespace character.
\w Match any "word" character: a-z, A-Z, 0-9 or underscore (_).
\W Match any non-word character.
\### Match the ascii character whose code is given or back-reference. Can be up to 3 octal digits.
Match back-reference if found. Match the prior group number given exactly. For example, ([:alpha:])\1 would match a double letter.
\x## Match the ascii character whose code is given in hexadecimal. Can be up to 2 digits.
\z Match only at end of string.
\Z Match only at end of string, or before newline at the end.
 

kaster

Мой Аватар, он лучший самый
Команда форума
Глобальный модератор
Сообщения
4,020
Репутация
626
OffTopic:
killbond [?]
Зато у StringRegExp возможности регулярных выражений шире!
одинаковые у них возможности. REGEXPTITLE и StringRegExp - используют один и тот же движок PCRE



Добавлено:
Сообщение автоматически объединено:

lightforever
Если тема решена, отмечай ее таковой
 
Верх