RogueX20 Posted June 11, 2011 Share Posted June 11, 2011 Reading up on stringregexp but I think there could be something else. I may have to do some supplemental reading as this might be a little advanced for newb. However once I've conquered this feet it will be something I actually use on a regular basis. And that will graduate me to the next level. Is there another function I should be looking at? For example I want to read a particular line in a file, so I use filereadline. In that line the first x amount of characters/words will always be the same. The next set of characters change then another word that stays the same. After that a change for a few words then one more word that stays the same. Example: Department XYZ has the following charge of 112.00 for Widget purchased on Oct 22, 2010 released to John Doe The characters that change are the characters/words I need to capture. XYX 112.00 Widget Oct 22, 2010 John Doe. Point me to the function that would put me on the right track if you can. Link to comment Share on other sites More sharing options...
Malkey Posted June 11, 2011 Share Posted June 11, 2011 Here is one or two methods using regular expressions.#include <Array.au3> Local $sString = "Department XYZ has the following charge of 112.00 for Widget purchased on Oct 22, 2010 released to John Doe" ;The characters that change are the characters/words I need to capture. XYX 112.00 Widget Oct 22, 2010 John Doe. ConsoleWrite(StringRegExpReplace($sString, "Department (.+) has the following charge of (.+) for (.+) purchased on (.+) released to (.+)", "\1 $2 \3 ${4} \5") & @CRLF) ;Or Local $aArray = StringRegExp($sString, "Department (.+) has the following charge of (.+) for (.+) purchased on (.+) released to (.+)", 3) _ArrayDisplay($aArray) Link to comment Share on other sites More sharing options...
GEOSoft Posted June 11, 2011 Share Posted June 11, 2011 It could be done with simple String* functions but in this case I thing a RegExp is the right way for you to go. If you want to practice working with SREs then look at the Toolkit in my signature. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
RogueX20 Posted June 11, 2011 Author Share Posted June 11, 2011 It could be done with simple String* functions but in this case I thing a RegExp is the right way for you to go.If you want to practice working with SREs then look at the Toolkit in my signature.Thanks I will look into now. This forum seems to be very helpful. Link to comment Share on other sites More sharing options...
RogueX20 Posted June 11, 2011 Author Share Posted June 11, 2011 (edited) StringSplit looks like a function I need. Edited June 11, 2011 by RogueX20 Link to comment Share on other sites More sharing options...
RogueX20 Posted June 11, 2011 Author Share Posted June 11, 2011 Here is one or two methods using regular expressions. #include <Array.au3> Local $sString = "Department XYZ has the following charge of 112.00 for Widget purchased on Oct 22, 2010 released to John Doe" ;The characters that change are the characters/words I need to capture. XYX 112.00 Widget Oct 22, 2010 John Doe. ConsoleWrite(StringRegExpReplace($sString, "Department (.+) has the following charge of (.+) for (.+) purchased on (.+) released to (.+)", "\1 $2 \3 ${4} \5") & @CRLF) ;Or Local $aArray = StringRegExp($sString, "Department (.+) has the following charge of (.+) for (.+) purchased on (.+) released to (.+)", 3) _ArrayDisplay($aArray) This is awesome! I was thinking along the wrong lines. I didn't realize it could be so simple. Going to test now, but if the Name includes a middle name will this work? That is the main thing I was looking to have worked into capturing correctly in the event the name happens to be first last or first middle and last or first middle initial and last. Going to test and give you my findings. You got me on a better path. Link to comment Share on other sites More sharing options...
RogueX20 Posted June 11, 2011 Author Share Posted June 11, 2011 MalKey you just turned up my interest in learning programming 100 fold. Link to comment Share on other sites More sharing options...
RogueX20 Posted June 11, 2011 Author Share Posted June 11, 2011 MalKey you just turned up my interest in learning programming 100 fold. Where did you read/learn to use (.+)? Had I saw something like that I would have did more reading on it. I wish I saw your post earlier. I overlooked it and didn't see it until a few minutes ago. Link to comment Share on other sites More sharing options...
RogueX20 Posted June 11, 2011 Author Share Posted June 11, 2011 MalKey you just turned up my interest in learning programming 100 fold. Where did you read/learn to use (.+)? Had I saw something like that I would have did more reading on it. I wish I saw your post earlier. I overlooked it and didn't see it until a few minutes ago. I found it. It's in the full listing of pcrepatterns. Great area to get more info. Link to comment Share on other sites More sharing options...
GEOSoft Posted June 11, 2011 Share Posted June 11, 2011 (edited) MalKey you just turned up my interest in learning programming 100 fold. Where did you read/learn to use (.+)? Had I saw something like that I would have did more reading on it. I wish I saw your post earlier. I overlooked it and didn't see it until a few minutes ago.It's standard RegEx. means any character+ means match 1 or more timesSo you end up with an expression that says match any character 1 or more times. That doesn't mean any specific character, just any character.Edit: By the way, look in the help file for StringRegExp() and you will see what can be used. Edited June 11, 2011 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" 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