MrKris1224 Posted August 23, 2014 Share Posted August 23, 2014 (edited) Hi, how to multireplace in autoit without words with 2 characters? Input: aaa %aaa% bbb %bbb% Output: xxx %aaa% xxx %bbb% StringRegExpReplace($sText, "[a],[b]","[x]) How?? @ I just want to not parse words containing % and : Edited August 23, 2014 by MrKris1224 Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2014 Share Posted August 23, 2014 Can you try to make your specification more precise please? MrKris1224 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
MrKris1224 Posted August 23, 2014 Author Share Posted August 23, 2014 (edited) I want to replace the letters a-z to %chrset:~X, 1%X = 0-24Apart from the words containing the character % and : Sorry i'am from poland it's google translator Input: @echo off ;replace this line echo Hello World %asdas% ;replace this line without %asdas% Output: %chrset:~X, 1%%chrset:~X, 1%%chrset:~X, 1%%chrset:~X, 1%%chrset:~X, 1% etc.%chrset:~X, 1%%chrset:~X, 1%%chrset:~X, 1%%chrset:~X, 1%%chrset:~X, 1%%asdas% etc. Edited August 23, 2014 by MrKris1224 Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2014 Share Posted August 23, 2014 If I understand you correctly you need to replace every word not enclosed with either % or : by a fixed string. But what does X = 0-24 mean? MrKris1224 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
MrKris1224 Posted August 23, 2014 Author Share Posted August 23, 2014 (edited) Yes, I want to replace every word except the word with a "%" or ":" But what does X = 0-24 mean? - It's not important Damn google translator xD @ echo asdasda ; replace this line :asasa ;no replace %asasa% ; no replace Edited August 23, 2014 by MrKris1224 Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2014 Share Posted August 23, 2014 (edited) Does this work for you? Local $s = "@echo off" & @CRLF & "echo Hello World %asdas%" Local $res = StringRegExpReplace($s, "(?m)((?<!:|%)[@[:alpha:]]++(?!%)\h*)", "%chrset:~X, 1%") ConsoleWrite($res & @LF) BTW how can the output serve any purpose? Edited August 23, 2014 by jchd MrKris1224 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
MrKris1224 Posted August 23, 2014 Author Share Posted August 23, 2014 No, it's result: %chrset:~X, 1%%chrset:~X, 1% %chrset:~X, 1%%chrset:~X, 1%%chrset:~X, 1%%asdas% Hmm... Replace letters: a = %chrset:~0, 1% b = %chrset:~1, 1% c = %chrset:~2, 1% (...) Words witch % or : character must be omitted abc ;replace to %chrset:~0, 1%%chrset:~1, 1%%chrset:~2, 1% abc %abc% ;replace to %chrset:~0, 1%%chrset:~1, 1%%chrset:~2, 1%%abc% :abc ;don't replace Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2014 Share Posted August 23, 2014 (edited) I'm slowly getting it now: you whish to replace every letter within words not preceeded by : or not enclosed by % by the string "%chrset:~" concatenated with the index of the letter starting with a = 1 then concatenated with ", 1%". BTW, there are 26 letters in a-z not 24 and how should we encode spaces, @ and other non-letters? In other words: what are you trying to achieve? Is that some way of re-encoding commands into another codepage? This is what I can do with your specifications as you exposed them: Local $s = "@echo off" & @CRLF & "echo Hello World %asdas%" Local $a = StringSplit($s, @CRLF, 3) For $i = 0 To UBound ($a) - 1 $a[$i] = Execute('"' & StringRegExpReplace($a[$i], "((?<!:|%)[@[:alpha:]]++(?!%)\h*)", '" & _LetterIdx("' & '\1' & '") & "') & '"') Next Local $res = _ArrayToString($a, @CRLF) ConsoleWrite($res & @LF) Func _LetterIdx($str) Local $a = StringToASCIIArray(StringLower($str)) For $i = 0 To UBound($a) - 1 $a[$i] = "%chrset:~" & ($a[$i] - Asc('a') + 1) & ", 1%" Next Return(_ArrayToString($a, "")) EndFunc Notice how @ and spaces are translated into negative values... Edited August 23, 2014 by jchd MrKris1224 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
MrKris1224 Posted August 23, 2014 Author Share Posted August 23, 2014 I'm slowly getting it now: you whish to replace every letter within words not preceeded by : or not enclosed by % by the string "%chrset:~" concatenated with the index of the letter starting with a = 1 then concatenated with ", 1%". BTW, there are 26 letters in a-z not 24 and how should we encode spaces, @ and other non-letters? In other words: what are you trying to achieve? Is that some way of re-encoding commands into another codepage? This is what I can do with your specifications as you exposed them: Local $s = "@echo off" & @CRLF & "echo Hello World %asdas%" Local $a = StringSplit($s, @CRLF, 3) For $i = 0 To UBound ($a) - 1 $a[$i] = Execute('"' & StringRegExpReplace($a[$i], "((?<!:|%)[@[:alpha:]]++(?!%)\h*)", '" & _LetterIdx("' & '\1' & '") & "') & '"') Next Local $res = _ArrayToString($a, @CRLF) ConsoleWrite($res & @LF) Func _LetterIdx($str) Local $a = StringToASCIIArray(StringLower($str)) For $i = 0 To UBound($a) - 1 $a[$i] = "%chrset:~" & ($a[$i] - Asc('a') + 1) & ", 1%" Next Return(_ArrayToString($a, "")) EndFunc Notice how @ and spaces are translated into negative values... Thank you. Were you able to almost achieve the expected goal.Problem 1: The "eats" spacesProblem 2: It does not have to be swapping characters to their counterparts in the Asc () only in numerical order in the alphabet - 1a = 0 (in alphabet = 1)b = 1c = 2d = 3etc.of course, with the annotation% chrset: ~ X, 1% Damn google translator sorry for thiat Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2014 Share Posted August 23, 2014 Is that better? Local $s = "@echo off" & @CRLF & "echo Hello World %asdas%" Local $a = StringSplit($s, @CRLF, 3) For $i = 0 To UBound ($a) - 1 $a[$i] = Execute('"' & StringRegExpReplace($a[$i], "((?<!:|%)[[:alpha:]]++(?!%))", '" & _LetterIdx("' & '\1' & '") & "') & '"') Next Local $res = _ArrayToString($a, @CRLF) ConsoleWrite($res & @LF) Func _LetterIdx($str) Local $a = StringToASCIIArray(StringLower($str)) For $i = 0 To UBound($a) - 1 $a[$i] = "%chrset:~" & ($a[$i] - Asc('a')) & ", 1%" Next Return(_ArrayToString($a, "")) EndFunc MrKris1224 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
MrKris1224 Posted August 23, 2014 Author Share Posted August 23, 2014 (edited) may be to split the input file into words and check if it contains the character % or : , or if so, it normally prescribed and if this is not turning? Ok it's work.Now the question is whether we can do so that it was impossible to select a file to open on a computer and then replace in him should all this function ?? then save it with the name of the note _For example:File.bat> File_.bat Edited August 23, 2014 by MrKris1224 Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2014 Share Posted August 23, 2014 What exactly is not correct with the latest script? MrKris1224 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
MrKris1224 Posted August 23, 2014 Author Share Posted August 23, 2014 I edit the post try to read Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2014 Share Posted August 23, 2014 (edited) You want to forbid use of the source bat and force redirect to the modified version? I don't know how you can do that, sorry. Maybe change the registry value for .bat files and launch this script with a Run() to launch the modified .bat? Edited August 23, 2014 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
MrKris1224 Posted August 23, 2014 Author Share Posted August 23, 2014 (edited) No, I just want to text input to convert a reading from the file and that was a possible option ybrania file from your computer FileOpenDialog () Edited August 23, 2014 by MrKris1224 Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2014 Share Posted August 23, 2014 Meaning is lost in translation. Which country are you from? Maybe try posting a new thread with a title for catching attention of native speakers. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
mikell Posted August 23, 2014 Share Posted August 23, 2014 Maybe Local $s = FileRead("File.bat") ;....code FileWrite("File_.bat", $res) ? MrKris1224 1 Link to comment Share on other sites More sharing options...
MrKris1224 Posted August 23, 2014 Author Share Posted August 23, 2014 (edited) About half of my problem solved. Now the only question is why part of my letters somewhere disappears ?? Test this code: #include <Array.au3> Local $s = FileOpenDialog("Wybierz plik do kodowania",@DesktopDir,"Pliki języka batch (*.bat)) If $s = "" Then Exit Local $a = StringSplit($s, @CRLF, 3) For $i = 0 To UBound ($a) - 1 $a[$i] = Execute('"' & StringRegExpReplace($a[$i], "((?<!:|%)[[:alpha:]]++(?!%))", '" & _LetterIdx("' & '\1' & '") & "') & '"') Next Local $res = _ArrayToString($a, @CRLF) ConsoleWrite($res & @LF) Func _LetterIdx($str) Local $a = StringToASCIIArray(StringLower($str)) For $i = 0 To UBound($a) - 1 $a[$i] = "%chrset:~" & ($a[$i] - Asc('a')) & ", 1%" Next Return(_ArrayToString($a, "")) EndFunc Most of the characters and the line disappears Sorry for polish words in program.Additionally, select the this file to "encode" and see the effects encoded, the program stops working This file to "encode": @echo off :: Bardzo ważna linia \/ setlocal enabledelayedexpansion :: wywołanie funkcji \/ call :split varka "teks,asdas fa,fasfa" "," :: zwrot liczby słów do %varka0% oraz wyświetlenie wszystkich za pomocą for \/ For /l %%A in (1,1,%varka0%) do (echo.!varka%%A!) pause>nul exit ::Tutaj zaczyna się funkcja. call :split nazwa zmiennej tekst rozdzielacz :split set "var_name=%~1" set vars=1 set chr=0 set text=%~2 set %var_name%0=1 set "delims=%~3" :loop_split set tmp=!text:~%chr%,1! If not defined tmp (goto :EOF) If "%tmp%"=="%delims%" (set/a vars+=1 set/a %var_name%0+=1) If "%tmp%"=="%delims%" (set "%var_name%%vars%=") else (set "%var_name%%vars%=!%var_name%%vars%!%tmp%") set/a chr+=1 goto loop_split Edited August 23, 2014 by MrKris1224 Link to comment Share on other sites More sharing options...
MrKris1224 Posted August 23, 2014 Author Share Posted August 23, 2014 Maybe write program in steps (sorry for my bad english): 1) Read source file 2) StringSplit using delimetrs " " (space) 3) Check word, if have chars: % or : then write normal word 4) If no have chars % or : then replace a-z to %chrset:~X,1% 5) if have other characters than a-z write other char normality Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2014 Share Posted August 23, 2014 That's because you specified only letters a-z. Polish language uses accents and these accented letters are stored as Unicode characters outside ASCII range when read from file. Try with this modified version: $a[$i] = Execute('"' & StringRegExpReplace($a[$i], "(*UCP)((?<!:|%)[\pL]++(?!%))", '" & _LetterIdx("' & '\1' & '") & "') & '"') Notice that for example letter ł gets translated to "%chrset:~146, 1%". This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now