Что нового

[Данные, строки] Вывод найденного текста из .tmp файла в MsgBox.

PreDoK

Новичок
Сообщения
30
Репутация
3
Столкнулся с проблемой не могу вывести текст из .tmp(прикреплен ниже).
Код:
$sFile = @ScriptDir & '*.tmp'

$hFile = FileOpen($sFile, 0)
$sText = FileRead($hFile)
FileClose($hFile)

$sVar_1 = StringRegExpReplace($sText, 'path=/\0\0\x1\x6inn-user=.*?; secure;', '')
MsgBox(0, 'ssssssss', $sVar_1)

В файле есть строки:
Найти мне надо выделеные красным цветом.
[General]
data="@Variant(\0\0\0\x7f\0\0\0\x16QList<QNetworkCookie>\0\0\0\0\x17\0\0\0\x5\0\0\0klauncher-login=derpont%40yandex.ru; expires=Thu, 10-Nov-2011 05:53:02 GMT; domain=launcher.4game.ru; path=/\0\0\0[selected-service=8; expires=Sun, 13-Nov-2011 08:23:43 GMT; domain=launcher.4game.ru; path=/\0\0\0[partner_id=5113173; expires=Fri, 11-Feb-2011 08:23:43 GMT; domain=launcher.4game.ru; path=/\0\0\x1\x6inn-user=[color=red]7FLTHd2f1_flWbDdJ5mBkg2yGMq-_etwfTG8YEUPYjBEmxVFyICPu8fDEN1Hf-Omu5egEDuYAY3R4DQ3K3uWE9MfzFm2pBG82ogo5MlEX5VcsStAmjKwwSsqimwsHgsCfROU-Cd9Bn5irhDa_KGYV8IupqOfuOen9T79hZG6IZO3;[/color] secure; expires=Sun, 28-Nov-2010 08:23:51 GMT; domain=launcher.4game.ru; path=/\0\0\0\x63inn-user-p=1296000; secure; expires=Sun, 28-Nov-2010 08:23:51 GMT; domain=launcher.4game.ru; path=/)"
 

r35p3ct

Продвинутый
Сообщения
228
Репутация
60
Попробуй так:
Код:
$sVar_1 = StringRegExpReplace($sText, '.*x6inn-user=(.*?); secure;.*', '\1')
MsgBox(0, 'ssssssss', $sVar_1)
 

aleratorio

Осваивающий
Сообщения
85
Репутация
43
Код:
$sFile = @ScriptDir & '*.tmp'

$hFile = FileOpen($sFile, 0)
$sText = FileRead($hFile)
FileClose($hFile)

;получаем всю строку от path до secure;
$arr = StringRegExp($sText, 'path=/\\0\\0\\x1\\x6inn-user=.*?; secure;', 1) ; \\ - дублируются
;удаляем лишнее
$sVar_1 = StringRegExpReplace($arr[0], 'path=/\\0\\0\\x1\\x6inn-user=| secure;', '')
MsgBox(0, 'ssssssss', $sVar_1)
 
Автор
P

PreDoK

Новичок
Сообщения
30
Репутация
3
aleratorio
Выдает это!
C:\Users\Tricker\Desktop\????? ????? (5)\AutoIt v3 Script.au3 (10) : ==> Variable used without being declared.:
$sVar_1 = StringRegExpReplace($arr[0], 'path=/\\0\\0\\x1\\x6inn-user=| secure;', '')
$sVar_1 = StringRegExpReplace(^ ERROR
>Exit code: 1 Time: 0.222
 

aleratorio

Осваивающий
Сообщения
85
Репутация
43
наверно потому что в первой строке надо -
Код:
$sFile = @ScriptDir & '\*.tmp'
поставить слеш перед *.tmp

я просто тестировал присваивая твой пример текста сразу переменной $sText не открывая файл, а верхнюю часть просто скопировал и не заметил ошибки.
 
Автор
P

PreDoK

Новичок
Сообщения
30
Репутация
3
Ты хоть у себя проверял?
Ошибка (10) : ==> Variable used without being declared.:
В этой строчке!
$sVar_1 = StringRegExpReplace($arr[0], 'path=/\\0\\0\\x1\\x6inn-user=| secure;', '')
$arr[0] - ты вобще от куда это взял?
 

aleratorio

Осваивающий
Сообщения
85
Репутация
43
я проверял вот так:

Код:
$sText = '[General] data="@Variant(\0\0\0\x7f\0\0\0\x16QList<QNetworkCookie>\0\0\0\0\x17\0\0\0\x5\0\0\0klauncher-login=derpont%40yandex.ru; expires=Thu, 10-Nov-2011 05:53:02 GMT; domain=launcher.4game.ru; path=/\0\0\0[selected-service=8; expires=Sun, 13-Nov-2011 08:23:43 GMT; domain=launcher.4game.ru; path=/\0\0\0[partner_id=5113173; expires=Fri, 11-Feb-2011 08:23:43 GMT; domain=launcher.4game.ru; path=/\0\0\x1\x6inn-user=7FLTHd2f1_flWbDdJ5mBkg2yGMq-_etwfTG8YEUPYjBEmxVFyICPu8fDEN1Hf-Omu5egEDuYAY3R4DQ3K3uWE9MfzFm2pBG82ogo5MlEX5VcsStAmjKwwSsqimwsHgsCfROU-Cd9Bn5irhDa_KGYV8IupqOfuOen9T79hZG6IZO3; secure; expires=Sun, 28-Nov-2010 08:23:51 GMT; domain=launcher.4game.ru; path=/\0\0\0\x63inn-user-p=1296000; secure; expires=Sun, 28-Nov-2010 08:23:51 GMT; domain=launcher.4game.ru; path=/)"'

;получаем всю строку от path до secure;
$arr = StringRegExp($sText, 'path=/\\0\\0\\x1\\x6inn-user=.*?; secure;', 1) ; \\ - дублируются
;удаляем лишнее
$sVar_1 = StringRegExpReplace($arr[0], 'path=/\\0\\0\\x1\\x6inn-user=| secure;', '')
MsgBox(0, 'ssssssss', $sVar_1)


а файл *.tmp - это надеюсь какой нибудь конкретный файл. не пишешь же ты прямо *.tmp
поставь после FileOpen - строку:
Код:
If $hFile = -1 Then MsgBox (0, "", "Не удалось открыть файл")

поймешь - открывает он его вообще или нет


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

PreDoK сказал(а):
$arr[0] - ты вобще от куда это взял?

отсюда:
StringRegExp
--------------------------------------------------------------------------------

Check if a string fits a given regular expression pattern.

StringRegExp ( "test", "pattern" [, flag ] [, offset ] ] )

Parameters

test The string to check
pattern The regular expression to compare.
flag [optional] A number to indicate how the function behaves. See below for details. The default is 0.
offset [optional] The string position to start the match (starts at 1) The default is 1.


Flag Values
0 Returns 1 (matched) or 0 (no match)
1 Return array of matches. <------------------------Вот отсюда
2 Return array of matches including the full match (Perl / PHP style).
3 Return array of global matches.
4 Return an array of arrays containing global matches including the full match (Perl / PHP style).
 
Автор
P

PreDoK

Новичок
Сообщения
30
Репутация
3
Все понял о чем ты спасибо!
Код:
$sFile = @ScriptDir & '\data.tmp'

$hFile = FileOpen($sFile, 0)
If $hFile = -1 Then MsgBox (0, "", "Не удалось открыть файл")
$sText = FileRead($hFile)
FileClose($hFile)

;получаем всю строку от path до secure;
$arr = StringRegExp($sText, 'path=/\\0\\0\\x1\\x6inn-user=.*?; secure;', 1) ; \\ - дублируются
;удаляем лишнее
$sVar_1 = StringRegExpReplace($arr[0], 'path=/\\0\\0\\x1\\x6inn-user=| secure;', '')
MsgBox(0, 'ssssssss', $sVar_1)




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

Можно еще узнать что вот это такое?
path=/\\0\\0\\x1\\x6inn-user=| secure;


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

aleratorio

Осваивающий
Сообщения
85
Репутация
43
здесь - $arr = StringRegExp($sText, 'path=/\\0\\0\\x1\\x6inn-user=.*?; secure;', 1) ты получаешь:
'path=/\\0\\0\\x1\\x6inn-user=нужный тебе текст; secure;'

а здесь ты $sVar_1 = StringRegExpReplace($arr[0], 'path=/\\0\\0\\x1\\x6inn-user=| secure;', '') удаляешь лишние фрагменты по краям. Символ | указывает что надо найти в строке соответствие с path=/\\0\\0\\x1\\x6inn-user=или secure; и заменить их на пустые строки ('')


скачай отсюда http://autoit-script.ru/index.php/topic,37.0.html книгу Дж. Фридла и все поймеш. Очень доступно описано ;)
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
PreDoK
Так покороче:
Код:
$hFile = FileOpen(@ScriptDir & '\data.tmp', 0)
$sText = FileRead($hFile)
FileClose($hFile)
$sUser = StringRegExpReplace($sText, '(?s).*?x6inn-user=(.*?) secure?.*', '\1')
MsgBox(0, '', $sUser)
Как еще r35p3ct предлагал.
 

aleratorio

Осваивающий
Сообщения
85
Репутация
43
Ну может быть. Я сам только начал в регулярных выражениях разбираться. Не все еще варианты знаю)))
 
Верх