AutID Posted November 13, 2013 Posted November 13, 2013 (edited) Hello,hmm i don't really know how to explain this :/I have a string like this$sText = "here as" $sString = "some text for me" & @LF & _ "some" & @LF & _ "and some other text here as well line test" & @LF & _ ;here "herealso" & @LF & _ "Sometesthere" & @LF & _ "artart43" & @LF & _ "aastreter " & @LF & _ "[dfg"I want to get the text from "other" until "line"I tried StringTrim functions but they do exactly what i thought they did.Local $stringpos = StringInStr($sString, $sText) If $stringpos Then $sString = 0 ;StringRegExpReplace pattern or something else which i don't know... ConsoleWrite($sString & @CRLF) Else ConsoleWrite("error" & @CRLF) EndIf Edited November 13, 2013 by AutID https://iblockify.wordpress.com/
Moderators Melba23 Posted November 13, 2013 Moderators Posted November 13, 2013 AutID,I would get that text like this:#include <Constants.au3> $sString = "some text for me" & @LF & _ "some" & @LF & _ "and some other text here as well line test" & @LF & _ ;here "herealso" & @LF & _ "Sometesthere" & @LF & _ "artart43" & @LF & _ "aastreter " & @LF & _ "[dfg" $sExtract = StringRegExpReplace($sString, "(?s).*other\s(.*)\sline.*", "$1") MsgBox($MB_SYSTEMMODAL, "Extract", $sExtract)SRER decode:(?s) - Treat newline strings (@CR/LF/CRLF) as any other .*other\s - Look for "other{space}" and then (.*) - capture all characters up to \sline.* - "(space)line" $1 - Replace everything with the capture groupI hope that helps. 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
Malkey Posted November 13, 2013 Posted November 13, 2013 Here is a non-regular expression method. Local $sString = "some text for me" & @LF & _ "some" & @LF & _ "and some other text here as well line test" & @LF & _ ;here "herealso" & @LF & _ "Sometesthere" & @LF & _ "artart43" & @LF & _ "aastreter " & @LF & _ "[dfg" Local $sStartWord = "other" Local $sLastWord = "line" Local $iStart = StringInStr($sString, $sStartWord) + StringLen($sStartWord) Local $sExtract = StringStripWS(StringMid($sString, $iStart, StringInStr($sString, $sLastWord) - $iStart), 3) MsgBox(0, "Extract", $sExtract)
mikell Posted November 13, 2013 Posted November 13, 2013 (edited) An other one #include <String.au3> Local $sString = "some text for me" & @LF & _ "some" & @LF & _ "and some other text here as well line test" & @LF & _ ;here "herealso" & @LF & _ "Sometesthere" & @LF & _ "artart43" & @LF & _ "aastreter " & @LF & _ "[dfg" Local $sExtract = _StringBetween($sString, "other", "line") MsgBox(0, "Extract", StringStripWS($sExtract[0], 3))) Edited November 13, 2013 by mikell
AutID Posted November 14, 2013 Author Posted November 14, 2013 (edited) Edit: Of course thank you all guys for the help and sorry for forgetting it :/I came up with this regular exprasion but it isn't excactly what i wanted to do.StringRegExpReplace($sString, "(?s).*\n(.*)\s.*", "$1")I want to look for a newline and then capture till a {space}. Shouldn't it be like this? Edited November 14, 2013 by AutID https://iblockify.wordpress.com/
kylomas Posted November 14, 2013 Posted November 14, 2013 AutID, "I want to look for a newline and then capture till a {space}." This will do that... #include <array.au3> $sText = "here as" $sString = "some text for me" & @LF & _ "some" & @LF & _ "and some other text here as well line test" & @LF & _ ;here "herealso" & @LF & _ "Sometesthere" & @LF & _ "artart43" & @LF & _ "aastreter " & @LF & _ "[dfg" local $array = stringregexp($sString,'(?m)\R(.*?) ',3) _arraydisplay($array) What if there is a n, followed by n-chrs, followed by a n (no intervening space)? 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
AutID Posted November 14, 2013 Author Posted November 14, 2013 AutID,"I want to look for a newline and then capture till a {space}."This will do that...#include <array.au3> $sText = "here as" $sString = "some text for me" & @LF & _ "some" & @LF & _ "and some other text here as well line test" & @LF & _ ;here "herealso" & @LF & _ "Sometesthere" & @LF & _ "artart43" & @LF & _ "aastreter " & @LF & _ "[dfg" local $array = stringregexp($sString,'(?m)\R(.*?) ',3) _arraydisplay($array)What if there is a n, followed by n-chrs, followed by a n (no intervening space)? kylomasYou missed to read the 1st post I am searching for a keyword in the text and then get the line from the beggining until the first space https://iblockify.wordpress.com/
kylomas Posted November 14, 2013 Posted November 14, 2013 Actually I read your first post and all of the WORKING solutions. It seemed that your requirements changed. Now I have no idea what you want. Good Luck, 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
AutID Posted November 14, 2013 Author Posted November 14, 2013 (edited) Actually I read your first post and all of the WORKING solutions. It seemed that your requirements changed. Now I have no idea what you want. Good Luck, kylomasOkGuys got it working. Thank you everyone. This is what i came up with:Local Const $stext = "has left" $diff = "some text for me" & @LF & _ "some" & @LF & _ "and some other Palclca (test) has left the text here as well line test" & @LF & _ ;here "herealso" & @LF & _ "Sometesthere" & @LF & _ "artart43" & @LF & _ "aastreter " & @LF & _ "[dfg" Local $stringpos = StringInStr($diff, $stext) Local $try = 0 If $stringpos Then Local $res $diff = StringRegExp($diff, "(?:([^\v]+)(?:\v+|$))", 3) If IsArray($diff) Then For $i = 0 To UBound($diff) - 1 If StringInStr($diff[$i], $stext) Then $res = $diff[$i] $res = StringRegExpReplace($res, "\s.*", "$1") ConsoleWrite($res & @CRLF) EndIf Next Else ConsoleWrite("Array doesn't exists" & @CRLF) EndIf Else ConsoleWrite("String doesn't exists" & @CRLF) EndIf Edited November 14, 2013 by AutID https://iblockify.wordpress.com/
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