Sign in to follow this  
Followers 0
RogueX20

Which Function?

10 posts in this topic

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 :huh2: 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. ;)

Share this post


Link to post
Share on other sites



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)

Share this post


Link to post
Share on other sites

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!"

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

StringSplit looks like a function I need.

Edited by RogueX20

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

MalKey you just turned up my interest in learning programming 100 fold. :huh2:

Share this post


Link to post
Share on other sites

MalKey you just turned up my interest in learning programming 100 fold. :huh2:

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.

Share this post


Link to post
Share on other sites

MalKey you just turned up my interest in learning programming 100 fold. :huh2:

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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

MalKey you just turned up my interest in learning programming 100 fold. :huh2:

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 times

So 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 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!"

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0