Jump to content

Search the Community

Showing results for tags 'StringRegExp'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • Forum FAQ
  • AutoIt

Calendars

  • Community Calendar

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

  1. Hi everyone, I have this string: "main_lot 0x111” & @CRLF & “main_version 0xABC” & @CRLF & “main_number 0xDEAD123” & @CRLF & “main_version 0x333" And I'm trying to extract one specific hexadecimal number, actually main_version from this string by using StringRegExp: How to get 'ABC' from it? I'm not sure if the original string uses @CRLF, @CR or @LF as a line breaks (received from linux over ssh plink.exe) I have tried this code but it doesn't work #include <Array.au3> $sLog = "main_lot 0x111” & @CRLF & “main_version 0xABC” & @CRLF & “main_number 0xDEAD123” & @CRLF & “main_version 0x333" $aVer = StringRegExp($sLog, "main_version\h*(.+)(?:0[xX][[:xdigit:]])", 3) _ArrayDisplay($aVer)
  2. Good morning I'm playing with SRE and trying to obtain some information from a test file. I was testing the pattern on regex101, but when I bring it to AutoIt, it doesn't return the same result as on regex101. I am surely (?:missing some important notes about PCRE engine|the pattern is not correct at all). Script: #include <Array.au3> #include <StringConstants.au3> Test() Func Test() Local $strFileName = @ScriptDir & "\TestFile.txt", _ $strFileContent, _ $arrResult $strFileContent = FileRead($strFileName) If @error Then Return ConsoleWrite("FileRead ERR: " & @error & @CRLF) $arrResult = StringRegExp($strFileContent, '(?sx)User:\h([^\n]+)\n' & _ 'Login\-name:\h([^\n]+)\n' & _ '(?:CaseSensitive:\h([^\n]+)\n)?' & _ 'NTSecurity:\h([^\n]+)\n' & _ '(?:NO\n)?' & _ '(?:Domain:\h([^\n]+)\n)?' & _ 'Timeout:\h([^\n]+)\n' & _ '.*?' & _ 'Member:\h([^\n]+)\n', $STR_REGEXPARRAYGLOBALMATCH) If IsArray($arrResult) Then _ArrayDisplay($arrResult) EndFunc Test file: User: AMMINISTRATORE Login-name: ADM CaseSensitive: YES NTSecurity: NO NO Timeout: 00:05:00 Member: AMMINISTRATORI User: Test_User Login-name: Test_User NTSecurity: YES Domain: DNEU Timeout: 00:00:00 Member: OPERATORS Member: OPERATORS Any help (even from cats) it's highly appreciated. Cheers
  3. Well the plan is to use the power of regular expressions engine of AutoIT for patching binary data. Something like this: StringRegExp( $BinaryData, "(?s)\x55\x8B.." <cut> ... Okay straight to question/problem ... certain bytes that are in the range from 0x80 to 0xA0 won't match. Hmm seem to be a char encoding problem. In detail these are 27 chars: 0x80, 0x82~8C, 0x8E, 0x91~9C, 0x9E,0x9F Here's a small code snippet to explore / explain this problem: #include "StringConstants.au3" $TestData = BinaryToString("0x7E7F808182") ;Okay $match = StringRegExp( $TestData ,'\x7E' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x7F' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x80' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x81' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x82' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;~ output: ;~ @extended = 2 $match = ;~ @extended = 3 $match = ;~ @extended = 0 $match = 1 ;~ @extended = 5 $match = ;~ @extended = 0 $match = 1 Hmm what to do? Go back and use the 'numberstring monster' implementation or just omit that range of 'unsafe bytes'. What is the root of this problem? Any idea how to fix this? Update: Okay I know a byte is not a character. But StringRegExp operates on String and so character level. Okay as long as you stay at Ansi encoding and only use /x00 - /X7F in the search pattern using StringRegExp works well to search for binary data. What bytes can be matched that are in the range from /X7F - /xFF is also depending on the code page. So this avoid to search for bytes in the range from 0x80-0xa0 only applies to Germany. I just change this country setting: to Thai and now near all bytes from /X7F - /xFF fails to match.
  4. i am trying to get number from string using this code : #include <IE.au3> $oIE = _IEAttach ("Edu.corner") Local $aName = "Student name & Code:", $iaName = "0" Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.InnerText = $aName Then $iaName = $oTd.NextElementSibling.InnerText $iGet = StringRegExpReplace($iaName, "\D", "") EndIf Next MsgBox(0, "", $iGet) it was get number like 52503058 But, I want to get only student code 5250. (Different student have different code, sometime its 3 digits, Sometime 4)
  5. Is there a way to output the regex matches into a file? I have a script to compare two files and check for regex matches. I want to output the matching regex of 'testexample.txt' to another file. #include <MsgBoxConstants.au3> #include <Array.au3> $Read = FileReadToArray("C:\Users\admin\Documents\testexample.txt") $Dictionary = FileReadToArray("C:\Users\admin\Documents\example.txt") For $p = 0 To UBound($Dictionary) - 1 Step 1 $pattern = $Dictionary[$p] For $i = 0 To UBound($Read) - 1 Step 1 $regex = $Read[$i] If StringRegExp($regex, $pattern, 0) Then MsgBox(0, "ResultsPass", "The string is in the file, highlighted strings: " ) Else MsgBox(0, "ResultsFail", "The string isn't in the file.") EndIf Next Next
  6. So I have this pattern: ^(?:(\d+)|(\d+):(\d+)|(\d+):(\d+):(\d+))$ And I'm expecting (depending on input) to get a 1, 2 or 3 index array (or @error for invalid input). But instead I get this: #include <Debug.au3> Func Test($String) _DebugArrayDisplay(StringRegExp($String, '^(?:(\d+)|(\d+):(\d+)|(\d+):(\d+):(\d+))$', 1)) EndFunc Test('10') ; Results (normal, expected): ; Row 0|10 Test('10:20') ; Results (extra blank index): ; Row 0| ; Row 1|10 ; Row 2|20 Test('10:20:30') ; Results (three blank indices): ; Row 0| ; Row 1| ; Row 2| ; Row 3|10 ; Row 4|20 ; Row 5|30 Is this normal? Should I just code around it, or is there a better way to do what I'm looking for? I also tried reversing my regex, but it was even uglier results: #include <Debug.au3> Func Test($String) _DebugArrayDisplay(StringRegExp($String, '^(?:(\d+):(\d+):(\d+))|(\d+):(\d+)|(\d+)$', 1)) EndFunc Test('10') ; Results (yuck): ; Row 0| ; Row 1| ; Row 2| ; Row 3| ; Row 4| ; Row 5|10 Test('10:20') ; Results (slightly better): ; Row 0| ; Row 1| ; Row 2| ; Row 3|10 ; Row 4|20 Test('10:20:30') ; Results (nice): ; Row 0|10 ; Row 1|20 ; Row 2|30
  7. Hi, I want to add any needed conditions to the StringRegExp command so it can pull out only "File.au3", "WinAPIFiles.au3", "Test.bmp" into the array #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include 'WinAPIFiles.au3' #include "File.au3" ; Script Start - Add your code below here Local $bFileInstall = False ; Change to True and ammend the file paths accordingly. ; This will install the file C:\Test.bmp to the script location. If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp") $sFile = FileRead(@ScriptFullPath) $aResults = StringRegExp($sFile, "(?i)(FileInstall\s*|include\s*)(.*)", 3) _ArrayDisplay($aResults) Thanks In Advance Deye
  8. i have a text : <Name>Jonh</Name>.<Age>15</Age> how i can get Jonh and 15 in one stringregexp? pls give me example
  9. I'm looking for a regex genius, cus I'm stumped when it comes to assertions. So what I have now, is this regular expression: ([^|=]+)=([^|]+) It takes a string (user input) of keys=values separated by pipes (ie: "param=value|param=value") and splits them into an array. Example: $vParamData = 'example=value|fruit=apple|phrase=Hello world' $aRegEx = StringRegExp($vParamData, '([^|=]+)=([^|]+)', 3) ; Result ; [0] => example ; [1] => value ; [2] => fruit ; [3] => apple ; [4] => phrase ; [5] => Hello world So that's working fine, but I'm wondering if there's also a way I could have this capture escaped pipes instead of splitting by them. ie: $vParamData = 'pipe test=this \| is a pipe|example=value' $aRegEx = StringRegExp($vParamData, '([^|=]+)=([^|]+)', 3) ; I'm getting this: ; [0] => pipe test ; [1] => this \ ; [2] => example ; [3] => value ; But I'd like a result like this: ; [0] => pipe test ; [1] => this \| is a pipe ; [2] => example ; [3] => value Is there some pattern that would accomplish this, or am I better off parsing it some other way?
  10. Hello, I have spent the past day fooling with StringRegExp to no avail attempting to get what would be a simple solution to an issue using StringRegExp. I will post the code in a sec. The string 'Java x Update y' where x and y are numeric values ONLY if a letter is mixed in anywhere then it should fail. I have been able to successfully deal with the x value so if x = 1234 or a1234 or 1a234 or 1234a would result in a fail if 'a' was in the string. However, when y = 1a234 then I get an output of 1 and when y = 1234a then the output = 1234 when both should fail. I am probably overlooking something simple and in looking through all the material and experimenting I am unable to figure it out and my experience with stringregexp and trying to find examples of this proved difficult. If someone could assist or point me to a thread ? Here is my code ; prob a simple fix. I am also trying to avoid white spaces. Thanks in advance #include <array.au3> $aArray = StringRegExp('Java 3009 Update 1a21', '(?i)Java (\d+) Update (\d+)', $STR_REGEXPARRAYGLOBALMATCH) If @error Then Exit _ArrayDisplay($aArray)
  11. Need help to make function better with full infomation #include <Array.au3> #include <File.au3> _TEST(@ScriptFullPath) _TEST("A:") _TEST("A:\B.c") _TEST("D:\E\F\") _TEST("G:\H/../J.k/") _TEST("M:\N\k..J.k") _TEST("D:\E\F\..\G\G\I..J.K.M") Func _TEST($sFilePath) Local $sDrive = "", $sFullPathDir = "", $sDirPath = "", $sDirName = "", $sFileName = "", $sFileNameExt = "", $sExtension = "", $sExt = "" Local $aPathSplit = _PathSplitByRef($sFilePath, $sDrive, $sFullPathDir, $sDirPath, $sDirName, $sFileName, $sFileNameExt, $sExtension, $sExt) ConsoleWrite("!Path IN : " & $sFilePath & @CRLF) ; C:\Windows\System32\etc\hosts.exe ConsoleWrite("- Driver : " & $sDrive & @CRLF) ; C: ConsoleWrite("- DirPath : " & $sFullPathDir & @CRLF) ; C:\Windows\System32\etc\etc ConsoleWrite("- DirPath : " & $sDirPath & @CRLF) ; \Windows\System32\etc\ ConsoleWrite("- DirName : " & $sDirName & @CRLF) ; etc ConsoleWrite("- FileName : " & $sFileName & @CRLF) ; hosts ConsoleWrite("- FileNameExt: " & $sFileNameExt & @CRLF) ; hosts.exe ConsoleWrite("- Extension : " & $sExtension & @CRLF) ; .exe ConsoleWrite("- Ext : " & $sExt & @CRLF & @CRLF) ; exe ;~ ConsoleWrite("!Path IN : " & $aPathSplit[0] & @CRLF) ; C:\Windows\System32\etc\hosts.exe ;~ ConsoleWrite("- Driver : " & $aPathSplit[1] & @CRLF) ; C: ;~ ConsoleWrite("- DirPath : " & $aPathSplit[2] & @CRLF) ; C:\Windows\System32\etc\etc ;~ ConsoleWrite("- DirPath : " & $aPathSplit[3] & @CRLF) ; \Windows\System32\etc\ ;~ ConsoleWrite("- DirName : " & $aPathSplit[4] & @CRLF) ; etc ;~ ConsoleWrite("- FileName : " & $aPathSplit[5] & @CRLF) ; hosts ;~ ConsoleWrite("- FileNameExt: " & $aPathSplit[6] & @CRLF) ; hosts.exe ;~ ConsoleWrite("- Extension : " & $aPathSplit[7] & @CRLF) ; .exe ;~ ConsoleWrite("- Ext : " & $aPathSplit[8] & @CRLF) ; exe ;~ _ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath) EndFunc ;==>_TEST Func _PathSplitByRef($sFilePath, ByRef $sDrive, ByRef $sFullPathDir, ByRef $sDirPath, ByRef $sDirName, ByRef $sFileName, ByRef $sFileNameExt, ByRef $sExtension, ByRef $sExt) If StringInStr($sFilePath,"..") Then $sFilePath=_PathFull($sFilePath) Local $aPartOfPath=StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH) ;~ If @error Then ReDim $aPartOfPath[9] ;~ $aPartOfPath[0] = $sFilePath ;~ EndIf $aPartOfPath[0] = $sFilePath ; C:\Windows\System32\etc\hosts.exe $sDrive = $aPartOfPath[1] ; C: $sFullPathDir = $aPartOfPath[1] & $aPartOfPath[2] ; C:\Windows\System32\etc If StringLeft($aPartOfPath[2], 1) == "/" Then $sDirPath = StringRegExpReplace($aPartOfPath[2], "\h*[\/\\]+\h*", "\/") Else $sDirPath = StringRegExpReplace($aPartOfPath[2], "\h*[\/\\]+\h*", "\\") EndIf $aPartOfPath[2] = $sFullPathDir ; C:\Windows\System32\etc $sDirName=StringReplace($sDirPath,"\","") $sDirName=StringReplace($sDirPath,"/","") $sFileName = $aPartOfPath[3] ; hosts $aPartOfPath[5] = $sFileName ; hosts $sExtension = $aPartOfPath[4] ; .exe $aPartOfPath[7] = $sExtension ; .exe $aPartOfPath[3] = $sDirPath ; \Windows\System32\etc\ $aPartOfPath[4] = $sDirName ; etc $aPartOfPath[6] = $sFileName & $sExtension ; hosts.exe $sFileNameExt = $aPartOfPath[6] ; hosts.exe $sExt = StringReplace($sExtension,".","") ; exe $aPartOfPath[8] = $sExt ; exe Return $aPartOfPath EndFunc ;==>_PathSplitByRef
  12. Does anyone know how to split a string using multiple delimiters, returning both the values and delimiters withing the Array using StringRegExp? For example: ;~ Split on " Not ", " And ", " Or " $sString = ' Not $a = 1 And $b = 2 Or $b = 3' $aArray = StringRegExp($sString,...) ;~ Returned Results $aArray[0] = '$a = 1' $aArray[1] = 'And' $aArray[2] = '$b = 2' $aArray[3] = 'Or' $aArray[4] = '$b = 3' At the moment I'm using Local $aArray1 = StringRegExp($sString, '(?i) Or | And | Not ', 3) Creating a new array using string split and then joining the two arrays together again Local $aArray1 = StringSplit(StringRegExpReplace($sString, '(?i) Or | And | Not ', '******'), '******', 3) Unfortunately regular expression isn't my forte.
  13. Hi, I need help string RegEx to get string from CREATE to GO #include <StringConstants.au3> ;~ Global $fileSQL1 = @ScriptDir & "\fileSQL1.sql" ;~ Global $fileSQL2 = @ScriptDir & "\fileSQL2.sql" Global $tmpSQLfile = @TempDir & "\tmpFile.sql" OnAutoItExitRegister("_OnExit") _SetTMPsql() If Not FileExists($tmpSQLfile) Then OnAutoItExitUnRegister("_OnExit") Exit MsgBox(48, "/!\", "File: " & $tmpSQLfile & @CRLF & " is not Exists!", 3) EndIf Global $ContentSQLfile = FileRead($tmpSQLfile) _Start() Func _Start() Local $aArray, $iOffset = 1, $stringRegExp = '(?i)CREATE(.*?)GO' While 1 $aArray = StringRegExp($ContentSQLfile, $stringRegExp, $STR_REGEXPARRAYMATCH, $iOffset) If @error Then MsgBox(48, "StringRegExp Error " & @error, "+> StringRegExp: " & $stringRegExp & @CRLF & @CRLF & "=> With STRING:" & @CRLF & @CRLF & $ContentSQLfile) ExitLoop EndIf $iOffset = @extended For $i = 0 To UBound($aArray) - 1 MsgBox(0, "RegExp Test with Option 1 - " & $i, $aArray[$i]) Next WEnd EndFunc ;==>_Start Func _SetTMPsql() Local $tmpSQLContent = "" $tmpSQLContent &= "USE [Master]" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "CREATE DATABASE [Sales] ON PRIMARY " & @CRLF $tmpSQLContent &= "( NAME = N’Sales’, FILENAME = N’\FSASQLDBSales.mdf’ , " & @CRLF $tmpSQLContent &= " SIZE = 2GB , MAXSIZE = 8GB, FILEGROWTH = 1GB )" & @CRLF $tmpSQLContent &= "LOG ON " & @CRLF $tmpSQLContent &= "( NAME = N’Sales_log’, FILENAME = N’\FSASQLDBSales_log.ldf’ , " & @CRLF $tmpSQLContent &= " SIZE = 1GB , MAXSIZE = 2GB , FILEGROWTH = 10%)" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "USE [Sales]" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "-- Table Product" & @CRLF $tmpSQLContent &= "CREATE TABLE [dbo].[Product]" & @CRLF $tmpSQLContent &= "(" & @CRLF $tmpSQLContent &= " [ProductId] [uniqueidentifier] DEFAULT NEWID() NOT NULL," & @CRLF $tmpSQLContent &= " [ProductName] [nchar](50) NULL," & @CRLF $tmpSQLContent &= " [ProductDescription] [nchar](3000) NULL," & @CRLF $tmpSQLContent &= " [ProductPrice] MONEY NULL" & @CRLF $tmpSQLContent &= ") ON [PRIMARY]" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "-- Table Sales" & @CRLF $tmpSQLContent &= "CREATE TABLE [dbo].[Sales]" & @CRLF $tmpSQLContent &= "( " & @CRLF $tmpSQLContent &= " [SaleId] [uniqueidentifier] DEFAULT NEWID() NOT NULL," & @CRLF $tmpSQLContent &= " [SaleName] [nchar](50) NULL," & @CRLF $tmpSQLContent &= " [SaleInfo] [nchar](3000) NULL," & @CRLF $tmpSQLContent &= " [SaleMoney] MONEY NULL" & @CRLF $tmpSQLContent &= ") ON [PRIMARY]" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "SET ANSI_NULLS ON" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "SET QUOTED_IDENTIFIER ON" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "-- The End" & @CRLF Local $hOpen = FileOpen($tmpSQLfile, 2 + 8 + 128) FileWrite($hOpen, $tmpSQLContent) Return FileClose($hOpen) EndFunc ;==>_SetTMPsql Func _OnExit() Exit FileDelete($tmpSQLfile) EndFunc ;==>_OnExit mikell
  14. Hi guys I hope you can help me out with this one. I have a text file "test.txt" which could contain something like this: __________________________________________________________ fiw eqw sdg xcv __________________________________________________________ Each string has it's own line. I use this script to find a string in the text file. In this example, the string I am looking for is "iw". The string "fiw" makes it believe that "iw" is found in the file. How can I avoid this? I want it only to return EXACT results. $string = "iw" $File = FileOpen("test.txt", 0) $ReadFile = FileRead($File) FileClose($File) If StringRegExp(StringLower($ReadFile), StringLower($string)) Then MsgBox(0,"",$string & " is found in the file") Exit Else MsgBox(0,"",$string & " is not found in the file") Exit EndIf
  15. Hello, try to remove all ASCII code and keep numbers. Read about StringRegExp and its flag, but best result is this: $mytxt = "Where have all the flowers gone, long time p33 976 7 6761assing? E#a%t^ m(y) {sh}o=rt\s" MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace($mytxt, "[a-z|A-Z|,|.]", "")) anyone can help me to obtain result = 3397676761 ? thank you, m.
  16. I do have a question <div class="col-sm-5 text-right"> <a href="/">IP Your adress: 113.228.141.182</a> </div> Is it true? (?U)(\d+\d+\.\d+\.\d+\.\d+.\.)
  17. hello, i'm new to this function so i need some help doing this, btw, i need to clear up my folder of work by deleting some files example file inside folder : info000001 to info999999 but i want to delete files name other than info(number) Func _delete() $dir = @ScriptDir & '\information' $cFiles = _FileListToArray($dir & '\', "*.xml", 1) If IsArray($cFiles) Then For $number To $cFiles[0] ;need to use StringRegExp here ;$stringRExp If $cFiles[$number] <> $stringRExp Then FileDelete($cFiles[$number] EndIf Next EndIf EndFunc
  18. how can I use the StringRegEx function to extract certain lines of text from google search results in the following format: C: server port user password an example is this: C: starteam.myftp.org 18000 test1 text2 regards
  19. Hello altogether, yes I already noticed the StringRegExp AutoIt reference and the very good german tutorial of SEuBo, but nevertheless I would be pleased to get a tip. I have strings like this: 'repair car "do it your self" check' or ' repair car toyota'. There could be none, one or more words in quotation marks. It could be also that no expression is set in quotation marks (-->" "). The words of the string vary. I would like to generate an array like [repair, car, do it your self, check] or [repair, car, toyota]. Expressions in quotation marks (" ") should not be splitted. Probably I could use string split and similar methods to combine the words in quotation marks afterwards. But that's not the way I'd like to do it. I already got this reg-exp to extract just the complete expressions in quotation marks (" ") to seperate these from the rest of the terms: Local $aExtract4 = StringRegExp($sTest4, '.*?"(.*?)".*?',3) Moreover I found this reg-exp to work similar to StringSplit with a " " as a delimiter. This would probably a solution if I didn't like to keep the terms in quotations marks together.... : Local $aExtract8 = StringRegExp($sTest4, '(.+?(?:\s|\z))',3) Nevertheless I failed to find a single reg-exp that is able to met both conditions. I am convincend that it is possible to design a single reg-exp that met both conditions! I already tried different scenarios with operators like or |, the conditional (?(?= ) clause and the use of assertion (Lookahead / -behind) but without success. I would appreciate a hint from an "reg-exp expert" if it's able to solve my problem with a single reg-exp and / or to give me some hints how to do that. Many thanks in advance. Auto42
  20. Hello, As always, sorry for my bad english. here is the code i have #include <File.au3> #include <String.au3> $file1 = "d:\doppioniautoit\international.txt" FileOpen($file1, 0) $file2 = "d:\doppioniautoit\standard.txt" FileOpen($file2, 0) For $i = 1 to _FileCountLines($file1) $line = FileReadLine($file1, $i) $aExtract = _StringBetween($line, "(", ")") ;MsgBox(0, $line, $aExtract[0]) $itime = TimerInit() For $x = 1 to _FileCountLines($file2) $line2 = FileReadLine($file2, $x) Local $iPosition = StringInStr($line2, $aExtract[0], 1) ;Local $iPosition = StringRegExp($line2,$aExtract[0], 0) if $iPosition <> 0 then ;MsgBox(0, "Trovato", $aExtract & " " & $line2) endif ConsoleWrite($line2 & @CRLF) Next ConsoleWrite(@TAB&'Str='&TimerDiff($itime)&' ms'&@lf) MsgBox(0, "TIME", @TAB&'Str='&TimerDiff($itime)&' ms'&@lf) Next FileClose($file1)So, what do i want to do? I try to explain with my poor english Basically, i have 2 text files (see attachments below). They both contains movie titles with Director and Year in this form Movie Title (Director, Year) "Standard.txt" contains, mostly, italian titles. "International.txt", as you can image, contains the internationals one. With the script i would like to search for the Director, Year of "international.txt" in the "standard.txt" file. For example... first row of "international.txt" is "¡Atraco! (Cortés, 2012)". The script takes just the "Cortés, 2012" and it searches for it in the standard. txt file. The simple code i wrote works... I tried using StringInStr and using StringRegExp.. they both need about 2 minutes and 30 seconds (stringinstr is little faster) to process one row. I was wondering... is there any other method to make it faster using autoit? Any help would be much appreciated, thx! standard.txt international.txt
  21. I have code $pattern = $str = "%abcd% = Section, hardwareID_1, hardwareID_2, ..... ,HardwareID_n" $array = StringRegExp( $str, $pattern, 3)Anyone help me with $pattern value I need $array is : No whitespace in all return string . (Sorry for my English) Thank you verymuch
  22. Hello, I am trying to create a regExp for following HTML text: <a href="link=1">1</a> <b>2</b> <a href="link=3">3</a> | <a href="link=2">Previous</a> | <a href="link=3">Next</a>My intention is to extract href from last <a> tag. Here is my attempt: Local $reg = '(?i)\|\s?<a href="(.*?)">Next</a>' Local $text = '<a href="link=1">1</a> <b>2</b> <a href="link=3">3</a> | <a href="link=2">Previous</a> | <a href="link=3">Next</a>' $aData = StringRegExp($text,$reg,3) ConsoleWrite($aData[0]&@LF)Now problem is i am unable to extract exact href from the last <a> tag. Here is the output: link=2">Previous</a> | <a href="link=3I know I can use other techniques, but i want to know, why my pattern is not working or what is the right pattern for such situation? Thanks in Advance.
  23. BackRef UDF Working This UDF is made to provide a small interface towards the StringRegExpReplace Autoit function. The extension is very limited but is an easy approach when used properly. Functions User can pass the complete back-reference to a function.The return value from the function is then used to replace the specific group.The final replacement is flexible and the user has full control over it.The final replacement is done automatically till modification isn't required.The optimization is easy and simple.LimitationsThe pattern has to consume the full string.Example Replace the vowels with their ASCII code #include <BackRef.au3> $i_BackRef_Debug = True ;Set Debug to true ; .. Example 1 ============================================================================================================================ ; Replace the vowels with their ASCII code Local $Replaced = RegExBackRef( 'Hello Nice Meeting You', '(.*?)([aeiou])(.*)', "AscW" ) ;The Function is inbuilt If @error Then Exit @error MsgBox ( 64, 'Test', $Replaced ) ; ............ ============================================================================================================================ Make the first Number group equal to second number group if its greater than that ; .. Example 2 ============================================================================================================================ ; The Function replaces the first group with third group if its greater than that Local $Replaced = RegExBackRef( '1223 MaxRange : 150', '(\d+)([^:]+:\h+)(\d+)', "SetMaxRange", '\1:\3', "$v & '\2\3'" ) If @error Then Exit @error MsgBox ( 64, 'Test', $Replaced ) ; The User Defined Function Func SetMaxRange( $iString ) $iString = StringSplit( $iString, ':' , 2) $iString[0] = Int ( $iString [0] ) $iString[1] = Int ( $iString [1] ) If $iString[0] > $iString[1] Then Return $iString[1] Return $iString[0] EndFunc ; ............ ============================================================================================================================ The Function replaces unicode chars with ascii alphabet ; .. Example 3 ============================================================================================================================ ; The Function replaces unicode version with ascii alphabet Local $String = 'Déjà' Local $Replaced While 1 $Replaced = RegExBackRef($String, '(.*?)([àâäéèêë])(.*)', "ReplaceFunc") If $Replaced = -1 Or @error Then ExitLoop $String = $Replaced WEnd MsgBox(64, 'Test', $String) Func ReplaceFunc($sMatch) Switch $sMatch Case "é","è","ê","ë" Return "e" Case "à","â","ä" Return "a" EndSwitch EndFunc ;==>ReplaceFunc ; ............ ============================================================================================================================ Convert the unicode lower-case chars to upper-case ; .. Example 4 ============================================================================================================================ ;Convert these chars to upper-case Local $String = "à æ û ü" MsgBox(64, 'Test', GlobalBackRef($String, '(.*?)([\340-\374])(.*)', "ReplaceUniChar")) Func ReplaceUniChar($sMatch) ;Get the ASCII code of the string $iAscW = AscW($sMatch) ;Return the character preceding the current character by 32 Return ChrW($iAscW - 32) EndFunc ;==>ReplaceUniChar ; ............ ============================================================================================================================ ChangeLog v1.0 -First Release v1.1 -Added Debugging features -Added Global Replacement v1.2 -Added Count parameter v1.3 -Now supports formatting control like \r \n and \t in the replace sequence. Download - UDF(v1.3) Here is the UDF to download in the following 7zip file. Please post comments and do give me feedback for improvements and bugs. v1.3 BackRef(UDF).7z Previous Downloads : 44 Regards Phoenix XL
  24. Hi, Trying to parse CSV here: https://regex101.com/r/mM2uP0/2, which gives desirable result, but SrtringRegExp output is a bit different (few empty strings have been returned): So my question would be why? And what's workaround if there's one? Thanks in advance!
  25. Good Afternoon Everyone, First and foremost, thank you for doing what you guys do. I use AutoIT almost every day. It helps the world out... so yes, thank you everyone, sincerely. This is my Regular Expression: <tr>.*(\n|\n.*\n)^<td>.*\n^<td>.*\d{1,2}\sJune\s2014.[\S\s]*?\n</tr> or <tr>.*(\n|\n.*\n)^<td>.*\n^<td>.*\d{1,2}\sMay\s2014.[\S\s]*?\n</tr> HTML CODE: </tr><tr><td><a onclick="s_objectID=&quot;http://support.apple.com/kb/HT6296_1&quot;;return this.s_oc?this.s_oc(e):true" href="http://support.apple.com/kb/HT6296">OS X Mavericks 10.9.4 and Security Update 2014-003</a></td> <td>OS X Lion v10.7.5, OS X Mountain Lion v10.8.5, OS X Mavericks 10.9 to 10.9.3</td> <td>30 June 2014</td> </tr><tr><td><a onclick="s_objectID=&quot;http://support.apple.com/kb/HT6293_1&quot;;return this.s_oc?this.s_oc(e):true" href="http://support.apple.com/kb/HT6293">Safari 6.1.5 and Safari 7.0.5</a></td> <td>OS X Lion v10.7.5, OS X Mountain Lion v10.8.5, OS X Mavericks v10.9.3</td> <td>30 June 2014</td> </tr><tr><td><p><a onclick="s_objectID=&quot;http://support.apple.com/kb/HT6254_1&quot;;return this.s_oc?this.s_oc(e):true" href="http://support.apple.com/kb/HT6254">Safari 6.1.4 and Safari 7.0.4</a></p> </td> <td>OS X Lion v10.7.5, OS X Mountain Lion v10.8.5, OS X Mavericks v10.9.3</td> <td><p>21 May 2014</p> </td> </tr><tr><td><p><a onclick="s_objectID=&quot;http://support.apple.com/kb/HT6248_1&quot;;return this.s_oc?this.s_oc(e):true" href="http://support.apple.com/kb/HT6248">OS X Server 3.1.2</a></p> </td> <td>OS X Mavericks 10.9.3 or later</td> <td><p>20 May 2014</p> </td> </tr><tr>This matches html with tags like <tr> , new lines \n as in Line Feed, digits \d, spaces \s, literal strings like "June" and any character .[\S\s]*? between zero and unlimited times. As I bash my head against the wall - I thank you for your help! PCRE regular expression engine updated to 8.34 #include <Array.au3> $test = "" $test &= '</tr><tr><td><a onclick="s_objectID=&quot;http://support.apple.com/kb/HT6296_1&quot;;return this.s_oc?this.s_oc(e):true" href="http://support.apple.com/kb/HT6296">OS X Mavericks 10.9.4 and Security Update 2014-003</a></td>' & @CRLF $test &= '<td>OS X Lion v10.7.5, OS X Mountain Lion v10.8.5, OS X Mavericks 10.9 to 10.9.3</td>' & @CRLF $test &= '<td>30 June 2014</td>' & @CRLF $test &= '</tr><tr><td><a onclick="s_objectID=&quot;http://support.apple.com/kb/HT6293_1&quot;;return this.s_oc?this.s_oc(e):true" href="http://support.apple.com/kb/HT6293">Safari 6.1.5 and Safari 7.0.5</a></td>' & @CRLF $test &= '<td>OS X Lion v10.7.5, OS X Mountain Lion v10.8.5, OS X Mavericks v10.9.3</td>' & @CRLF $test &= '<td>30 June 2014</td>' & @CRLF $test &= '</tr><tr><td><p><a onclick="s_objectID=&quot;http://support.apple.com/kb/HT6254_1&quot;;return this.s_oc?this.s_oc(e):true" href="http://support.apple.com/kb/HT6254">Safari 6.1.4 and Safari 7.0.4</a></p>' & @CRLF $test &= '</td>' & @CRLF $test &= '<td>OS X Lion v10.7.5, OS X Mountain Lion v10.8.5, OS X Mavericks v10.9.3</td>' & @CRLF $test &= '<td><p>21 May 2014</p>' & @CRLF $test &= '</td>' & @CRLF $test &= '</tr><tr><td><p><a onclick="s_objectID=&quot;http://support.apple.com/kb/HT6248_1&quot;;return this.s_oc?this.s_oc(e):true" href="http://support.apple.com/kb/HT6248">OS X Server 3.1.2</a></p>' & @CRLF $test &= '</td>' & @CRLF $test &= '<td>OS X Mavericks 10.9.3 or later</td>' & @CRLF $test &= '<td><p>20 May 2014</p>' & @CRLF $test &= '</td>' & @CRLF $test &= '</tr><tr>' & @CRLF MsgBox (0,"", $test) $AppleMonthName = "June" Local $aArray = StringRegExp ($test, '<tr>.*\n<td>.*\n<td>\d\d\s' & $AppleMonthName & '\s2014</td>\n</tr>', $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aMatch = 0 For $i = 0 To UBound($aArray) - 1 $aMatch = $aArray[$i] For $j = 0 To UBound($aMatch) - 1 MsgBox($MB_SYSTEMMODAL, "RegExp Test with Option 4 - " & $i & ',' & $j, $aMatch[$j]) Next Next $AppleMonthName = "May" Local $aArray = StringRegExp ($test, '<tr>.*\n<td>.*\n<td>\d\d\s' & $AppleMonthName & '\s2014</td>\n</tr>', $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aMatch = 0 For $i = 0 To UBound($aArray) - 1 $aMatch = $aArray[$i] For $j = 0 To UBound($aMatch) - 1 MsgBox($MB_SYSTEMMODAL, "RegExp Test with Option 4 - " & $i & ',' & $j, $aMatch[$j]) Next Next Exit
×
×
  • Create New...