Auio42TheWin Posted March 2, 2015 Posted March 2, 2015 Hello, people. I have been searching the forums for an example of how to do this, but I just don't know how to word it. I have found examples of how to search a text file for how many occurences of a word appears, but how do I do that and trim around it in certain directions? Gah. It's so confusing trying to explain. Let's say I have a text file that saids this : dasdsad4|62530 No. 342344|62530 Teehee. fsdfsd4|62530 I don't care. gdfgd4|62530 So much pie! 23234|62530 Okay fsdfs4|62530 Please give me pie. adasd4|62530 Just watch 23234|62530 Autoit Rocks. asdasd4|62530 heh 23234|62530 LOL How would I search for each occurrence of "4|62530" and delete all text to the left of it and "4|62530" itself to leave me with just a word like " Please give me pie." and consolewrite each? I'm not asking to be spoonfed, really, I wish I could do this on my own. But I really just don't know where to start, and I'm low on time right now
Moderators Melba23 Posted March 2, 2015 Moderators Posted March 2, 2015 (edited) Auio42TheWin,One way might be like this: #include <StringConstants.au3> $sString = "dasdsad4|62530 No." & @CRLF & _ "342344|62530 Teehee." & @CRLF & _ "fsdfsd4|62530 I don't care." & @CRLF & _ "gdfgd4|62530 So much pie!" & @CRLF & _ "23234|62530 Okay" & @CRLF & _ "fsdfs4|62530 Please give me pie." & @CRLF & _ "adasd4|62530 Just watch" & @CRLF & _ "23234|62530 Autoit Rocks." & @CRLF & _ "asdasd4|62530 heh" & @CRLF & _ "23234|62530 LOL" ; Convert to an array $aLines = StringSplit($sString, @CRLF, $STR_ENTIRESPLIT) ; And loop through each line For $i = 1 To $aLines[0] ; Extract line $sLine = $aLines[$i] ; Does it contain the required string If StringInStr($sLine, "4|62530") Then ; If so, then extract the text ConsoleWrite(StringRegExpReplace($sLine, ".*4\|62530\s(.*)", "$1") & @CRLF) EndIf NextNow we wait for the real RegEx gurus to do it on one pass. M23 Edited March 2, 2015 by Melba23 Typo Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
l3ill Posted March 2, 2015 Posted March 2, 2015 Regular expressions is the word you are looking for... But if you are in a hurry thats a lot to learn. You could play around with the String functions: StringInString StringSplit etc good luck ! Bill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
iamtheky Posted March 2, 2015 Posted March 2, 2015 (edited) #include<file.au3> Global $aFile _FileReadToArray("test.txt" , $aFile) for $i = 1 to $aFile[0] If stringinstr($aFile[$i] , "4|62530") Then consolewrite(StringRegExpReplace($aFile[$i] , ".*?4\|62530" , "") & @CRLF) next damn im slow, at least i was close to the reasonable suggestion.. Edited March 2, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Auio42TheWin Posted March 2, 2015 Author Posted March 2, 2015 (edited) Auio42TheWin, One way might be like this: #include <StringConstants.au3> $sString = "dasdsad4|62530 No." & @CRLF & _ "342344|62530 Teehee." & @CRLF & _ "fsdfsd4|62530 I don't care." & @CRLF & _ "gdfgd4|62530 So much pie!" & @CRLF & _ "23234|62530 Okay" & @CRLF & _ "fsdfs4|62530 Please give me pie." & @CRLF & _ "adasd4|62530 Just watch" & @CRLF & _ "23234|62530 Autoit Rocks." & @CRLF & _ "asdasd4|62530 heh" & @CRLF & _ "23234|62530 LOL" ; Convert to an array $aLines = StringSplit($sString, @CRLF, $STR_ENTIRESPLIT) ; And loop through each line For $i = 1 To $aLines[0] ; Extract line $sLine = $aLines[$i] ; Does it contain the required string If StringInStr($sLine, "4|62530") Then ; If so, then extract the text ConsoleWrite(StringRegExpReplace($sLine, ".*4\|62530\s(.*)", "$1") & @CRLF) EndIf Next Now we wait for the real RegEx gurus to do it on one pass. M23 what if all the text was like all on one line? (imagine what I'm about to show you not being word-wrapped) like on one line in a text document http://www.example.com/Something/?test=31117267;http://www.example.com/Something/?test=20642008;http://www.example.com/Something/?test=77800124;http://www.example.com/Something/?test=9255011;http://www.example.com/Something/?test=119509981;http://www.example.com/Something/?test=119509901 and all I wanted to get was the numbers following "?test" and print each one individually? I'm sorry if I'm confusing you, I don't think I'm very good at wording this stuff. Edited March 2, 2015 by Auio42TheWin
Moderators Melba23 Posted March 2, 2015 Moderators Posted March 2, 2015 Auio42TheWin,Just post a file - those links do not work. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Auio42TheWin Posted March 2, 2015 Author Posted March 2, 2015 Auio42TheWin, Just post a file - those links do not work. M23 oh they weren't real links, haha. they were just examples. sorry if i confused you.
Moderators Melba23 Posted March 2, 2015 Moderators Posted March 2, 2015 Auio42TheWin,It is really easy to do that with a simple RegEx. But how about explaining what you are actually trying to do - we do not appreciate producing umpteen solutions to random questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
iamtheky Posted March 2, 2015 Posted March 2, 2015 #include <Array.au3> $sString="http://www.example.com/Something/?test=31117267;http://www.example.com/Something/?test=20642008;http://www.example.com/Something/?test=77800124;http://www.example.com/Something/?test=9255011;http://www.example.com/Something/?test=119509981;http://www.example.com/Something/?test=119509901" $aMatch = StringRegExp($sString , "test=(.*?);|test=(.*?)\z" , 3) for $i = 0 to ubound($aMatch) - 1 If $aMatch[$i] <> "" Then consolewrite($aMatch[$i] & @CRLF) next the regex is dirty cause i am teh suck at them. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Auio42TheWin Posted March 2, 2015 Author Posted March 2, 2015 (edited) Auio42TheWin, It is really easy to do that with a simple RegEx. But how about explaining what you are actually trying to do - we do not appreciate producing umpteen solutions to random questions. M23 My dad saves a collection of links to a text file, and just copies and pastes them on one line and separates them using ";". (no idea why) All he needs is the numbers. He does this on a separate computer, and he does this occasionally, so that's how I know. I want to figure out how to get the numbers behind each link separately. So I was thinking about it, and I was all like "Dad, I think I could figure out how to do this" since I know of AutoIt. I've been trying to find a solution. This would help him, and me as I could use this in the future if I came across a problem like this again. Edited March 2, 2015 by Auio42TheWin
Moderators Melba23 Posted March 2, 2015 Moderators Posted March 2, 2015 Auio42TheWin,Then why all the guff at the beginning about "pie"? We much prefer that you give us the real information straight away. This should work: #include <Array.au3> $sString = "http://www.example.com/Something/?test=31117267;http://www.example.com/Something/?test=20642008;http://www.example.com/Something/?test=77800124;http://www.example.com/Something/?test=9255011;http://www.example.com/Something/?test=119509981;http://www.example.com/Something/?test=119509901" $aRet = StringRegExp($sString, "(\d+)", 3) _ArrayDisplay($aRet, "", Default, 8)M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
iamtheky Posted March 2, 2015 Posted March 2, 2015 (edited) and you could always run a script on his box so that when he copies the url, only the number remains to be pasted while 1 If stringinstr(clipget() , "?test=") Then clipput(StringRegExp(clipget() , "test=(\d+)" , 3)[0]) sleep(30) wend Edited March 2, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Auio42TheWin Posted March 2, 2015 Author Posted March 2, 2015 Auio42TheWin, Then why all the guff at the beginning about "pie"? We much prefer that you give us the real information straight away. This should work: #include <Array.au3> $sString = "http://www.example.com/Something/?test=31117267;http://www.example.com/Something/?test=20642008;http://www.example.com/Something/?test=77800124;http://www.example.com/Something/?test=9255011;http://www.example.com/Something/?test=119509981;http://www.example.com/Something/?test=119509901" $aRet = StringRegExp($sString, "(\d+)", 3) _ArrayDisplay($aRet, "", Default, 8) M23 Sorry, the only reason I gave the example with "pie" is because I couldn't think of a better way to explain it. I'm stupid. I thought I was making it easier. Thanks!
Auio42TheWin Posted March 2, 2015 Author Posted March 2, 2015 and you could always run a script on his box so that when he copies the url, only the number remains to be pasted while 1 If stringinstr(clipget() , "?test=") Then clipput(StringRegExp(clipget() , "test=(\d+)" , 3)[0]) sleep(30) wend Awesome, that's like putting the cherry ontop of the pie! Thank you, Both and Melba!
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