HurleyShanabarger Posted October 7, 2014 Share Posted October 7, 2014 Hello, i have a huge amount of data to process. My goal is it to turn this This is a text @1234@ seperated by some @7890@ strange looking @8755@ constructions. into this This is a text @1@ seperated by some @2@ strange looking @3@ constructions. I am able to replace the @####@ data with this piece of code: $sString = "This is a text @1234@ seperated by some @7890@ strange looking @8755@ constructions." $sResult = StringRegExpReplace($sString, "@[0-9]{4}@", "\n", 0) Is there anyway to achieve my goal using StringRegExReplace? Thanks for some hints. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 7, 2014 Moderators Share Posted October 7, 2014 HurleyShanabarger,Welcome to the AutoIt forums. I fear you may have to do some additional processing: #include <StringConstants.au3> $sString = "This is a text @1234@ seperated by some @7890@ strange looking @8755@ constructions." ; Replace all instances of "@nnnnn@" with a single unique string $sReplaced = StringRegExpReplace($sString, "@[0-9]{4}@", "@#####@", 0) ; Split the string on that unique string $aSplit = StringSplit($sReplaced, "@#####@", $STR_ENTIRESPLIT) ; Reconstruct the string adding the increasing count value $sResult = "" For $i = 1 To $aSplit[0] - 1 $sResult &= $aSplit[$i] & "@" & $i & "@" Next $sResult &= $aSplit[$i] ConsoleWrite($sResult & @CRLF)But no doubt some RegEx guru will be along in a minute to show us mere mortals how it can be done. 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 Link to comment Share on other sites More sharing options...
mikell Posted October 7, 2014 Share Posted October 7, 2014 ? $sString = "This is a text @1234@ seperated by some @7890@ strange looking @8755@ constructions." $n = 0 While 1 $n += 1 $sString = StringRegExpReplace($sString, "(?<=@)\d{4}(?=@)", $n, 1) If @extended = 0 Then Exitloop Wend Msgbox(0,"", $sString) Link to comment Share on other sites More sharing options...
jchd Posted October 7, 2014 Share Posted October 7, 2014 The specification is ambiguous. Do you want to replace successive occurrences of @dddd@ by successive values @1@, @2@, @3@, ... like mikell did or do you pick digits from the first occurrence for replacement? In other words, what should be the outcome of: This is a text @6543@ seperated by some @7890@ strange looking @8755@ constructions. This? This is a text @1@ seperated by some @2@ strange looking @3@ constructions. That? This is a text @6@ seperated by some @5@ strange looking @4@ constructions. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
kylomas Posted October 7, 2014 Share Posted October 7, 2014 (edited) Also, Does a "@" always delimit the chars you want to replace? Is the replaced pattern always 4 digits? edit: A real life example (sample of your file) might b helpful. Edited October 7, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
HurleyShanabarger Posted October 7, 2014 Author Share Posted October 7, 2014 Hi there, the solution of mikell is exactly what I need. Thanks a lot, mate. I am sorry, that the description was not very clear. The speed is also awesome - exactly what I needed! Link to comment Share on other sites More sharing options...
HurleyShanabarger Posted October 13, 2014 Author Share Posted October 13, 2014 Hey guys, I got another one for you. The data that I want to examine now is build similar like this: <field XXXXXXX>Text<More nested stuff></field><field YYYYYY>test</field> What i want to retrieve now is this: [0] = <field XXXXXXX>Text<More nested stuff></field> [1] = <field YYYYYY>test</field> I tried it with this piece of code, but that is not helping me: $_l_sString = '<field XXXXXXX>Text<More nested stuff></field><field YYYYYY>test</field>' $_l_aResult = StringRegExp($_l_sString , "(?<=\<field)(.*)(?=\<\/field>)", 1) Any hints for me? Thanks again! Link to comment Share on other sites More sharing options...
jchd Posted October 13, 2014 Share Posted October 13, 2014 That? #include <Array.au3> $_l_sString = '<field XXXXXXX>Text<More nested stuff></field><field YYYYYY>test</field>' $_l_aResult = StringRegExp($_l_sString , "(<field.*?/field>)", 3) _ArrayDisplay($_l_aResult) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jguinch Posted October 13, 2014 Share Posted October 13, 2014 (edited) @Mikell : the OP said i have a huge amount of data to process, so maybe it's possible to have more than 999 replacements. In this case, your code won't work properly. But Melba's code will do the job perfectly. Sorry for the joke ... Just add a replacement to avoid this (a mix of Melba's and Mikell's code): $sString = "This is a text @1234@ seperated by some @7890@ strange looking @8755@ constructions." $n = 0 While 1 $n += 1 $sString = StringRegExpReplace($sString, "(?<=@)\d{4}(?=@)", "#" & $n & "#", 1) If @extended = 0 Then Exitloop Wend $sString = StringRegExpReplace($sString, "@#(\d+)#@", "@$1@") Msgbox(0,"", $sString) Edited October 13, 2014 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
jdelaney Posted October 13, 2014 Share Posted October 13, 2014 Do a forum search for XMLDOM. Lots of examples of parsing XML. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
jguinch Posted October 13, 2014 Share Posted October 13, 2014 (edited) I tried to launch the replacement with my code with a file containing 10000 lines : it's very slow With this following code, it's really faster (just one global remplacement and one Execute) : $sString = "This is a text @1234@ seperated by some @7890@ strange looking @8755@ constructions." $sOutput = "'" & StringReplace($sString, "'", "''") & "'" $sOutput = Execute ( StringRegExpReplace($sOutput , "(?<=@)\d+(?=@)", "' & Assign(""iReplace"", Eval(""iReplace"") + 1) * 0 + Eval(""iReplace"") & '") ) MsgBox(0, "", $sOutput) Edited October 13, 2014 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted October 13, 2014 Share Posted October 13, 2014 Wow Your mastering of quotes is amazing Link to comment Share on other sites More sharing options...
jguinch Posted October 13, 2014 Share Posted October 13, 2014 Thx ! I know you hate quotes ... Now, for my code, i didn't invent anything. It's the JCHD's touch ! http://www.autoitscript.fr/forum/viewtopic.php?p=80747#p80747 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
jchd Posted October 13, 2014 Share Posted October 13, 2014 I doubt I'm at the root of Execute(StringRegexp...), in AutoIt ot whatever other language. We just borrow/inherit from piles of geniuses. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jguinch Posted October 13, 2014 Share Posted October 13, 2014 Note at the root, of course. But your idea was particulary brilliant (small code, very fast, and easy to understand) ! Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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