dmob Posted March 12, 2021 Posted March 12, 2021 (edited) I have a string and need to extract, process and finally replace all substrings between, and including the { } I was hoping to use RegEx but cannot figure out how repeat the search pattern. #include <Array.au3> Local $sPatt = "({(.*)}" ; "(?:{(.*)})" Local $sString = "{A.Item}, R{B.Some} {B.Other} text string {C.Date} {C.Item}{C.Thing}" Local $aArray = StringRegExp($sString, $sPatt, 3) _ArrayDisplay($aArray) My goal is an array with: {A.Item} {B.Some} {B.Other} {C.Date} {C.Item} {C.Thing} Edited March 12, 2021 by dmob
Nine Posted March 12, 2021 Posted March 12, 2021 This ? #include <Array.au3> $txt = "{A.Item}, R{B.Some} {B.Other} text string {C.Date} {C.Item}{C.Thing}" $arr = StringRegExp($txt,"({[^}]*})", 3) _ArrayDisplay($arr) dmob 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
pixelsearch Posted March 12, 2021 Posted March 12, 2021 @dmob : imho you were nearly there : #include <Array.au3> $txt = "{A.Item}, R{B.Some} {B.Other} text string {C.Date} {C.Item}{C.Thing}" $arr1 = StringRegExp($txt,"({[^}]*})", 3) _ArrayDisplay($arr1, "Nine's negated way") $arr2 = StringRegExp($txt,"(?U)({.*})", 3) _ArrayDisplay($arr2, "Lazy way #1") $arr3 = StringRegExp($txt,"({.*?})", 3) _ArrayDisplay($arr3, "Lazy way #2") dmob 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
dmob Posted March 13, 2021 Author Posted March 13, 2021 @pixelsearch Thank you for the lesson, always good to learn other methods pixelsearch 1
pixelsearch Posted March 13, 2021 Posted March 13, 2021 Always a pleasure to share what we can with nice people "I think you are searching a bug where there is no bug... don't listen to bad advice."
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