Jump to content

Search and Parse text within a file


Recommended Posts

I really am new to this. I've searched the forums and google for this answer and I can't seem to find anything that fits. Thankfully in the past when using AutoIT I have always been able to pirate someones code and make it work for what I've been doing.

So what it boils down to is this, I'm pulling an RSS feed to a txt file using _INetGetSource, that comes down no problem. What I am then trying to do is search that file, feed.txt for 12 characters. These characters are random, contain letters and numbers, but are always contained between /> and <br. I've been looking at StringRegExp and StringInStr and even with the examples it is a little over my head.

And then from there I'm trying to take its finding and put them into a text file.

If someone could point me in the right direction that would be awesome. If I am asking to much and need to keep searching, I understand.

Thanks

Edited by mrgrosser
Link to comment
Share on other sites

  • Moderators

mrgrosser,

Welcome to the AutoIt forum. :mellow:

This works for me: :)

$sString = "blah blah blah />123456789012<br blah blah blah"

$sText = StringRegExpReplace($sString, ".*>(.*)&lt.*", "$1")

ConsoleWrite($sText & @CRLF

If you want to learn about SREs, I recommend this website. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ok, maybe I'm not understanding this properly, but I've been reading through your recommended website on SRE's... and now I'm not understanding even more. the line of $sString = "blah blah blah />123456789012<br blah blah blah" would denote that is what I'm looking for when in reality it is a set of 12 random letters and numbers wrapped in /> and <br. So wouldn't the string be more like $sString = "blah blah blah />[A-Z0-9]{12}<br blah blah blah" or am I reading this completely wrong. Or is it in the StringRegExpReplace that I need to put that [A-Z0-9]{12} expression?

Thanks

Link to comment
Share on other sites

If it only occurs once on the page then a StringRegExpReplace() should do it otherwise you will want a StringRegExp() with the flag probably set to 3.

This should be a decent expression but without seeing the actual page there is no sure way of knowing.

$s_String = StringRegExpReplace(FileRead("C:Some\Path\File.txt", "(?si)^.*>\h*([[:alnum:]]{12})\h*<.*$", "$1")

For a RegEx only then "(?i)>\h*([[:alnum:]]{12})\h*<"

EDIT Added a check for horizontal spaces before and after in case of poor html.

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

Link to comment
Share on other sites

Thank you very much this is getting me going. Since I have no idea what ConsoleWrite does now I am on to writing $sText to a file. I appreciate the help and pointing me in the right direction!

Run the script from SciTE, the console should be at the bottom, if it isn't, click View > Output (or F8).
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...