Moderators Melba23 Posted December 18, 2015 Moderators Posted December 18, 2015 kylomas,I think I was right about the "\K" - if we protect the characters by capturing them and then adding them to the replacement it also works:StringRegExpReplace($sString, "(.{1," & $x - 1 & "})(\s{1,2}|$)", "$1" & @CRLF)So when the Help file speaks of "similar but not identical to a look-behind" it means that "\K" protects the previous group just as does a "look-behind/ahead" structure.Brain slowly recovering. Now if only the excellent Gewurztraminer I have been drinking could act as a blood transfusion.....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
Gianni Posted December 18, 2015 Posted December 18, 2015 one more way...Local $sString = 'A child asked his father, "How were people born?" So his father said, "Adam and Eve made babies, then their babies became adults and made babies, and so on." The child then went to his mother, asked her the same question and she told him, "We were monkeys then we evolved to become like we are now." The child ran back to his father and said, "You lied to me!" His father replied, "No, your mom was talking about her side of the family."' $x = 74 For $i = $x to StringLen($sString) Step $x $i = StringInStr($sString, " ", 0, -1, $i) $sString = StringReplace($sString, $i, @CR) Next MsgBox(0, '', $sString) mikell 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
kylomas Posted December 18, 2015 Posted December 18, 2015 So when the Help file speaks of "similar but not identical to a look-behind" it means that "\K" protects the previous group just as does a "look-behind/ahead" structure."I see", said the blind man as he picked up his hammer and saw... 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
iamtheky Posted December 18, 2015 Posted December 18, 2015 Now if only the excellent Gewurztraminer I have been drinking could act as a blood transfusion.....Caduceus (Maynard James Keenan of Tool's winery) has a Merkin Chupacabra Blanca that is part gewurztraminer, part Riesling. Best I've had since i left Europe. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
mikell Posted December 18, 2015 Posted December 18, 2015 Melba,Your guess is right \K is a pretty nice thing. In a SRER all chars mentioned in the pattern before \K are 'protected' indeedA little example : let's say you want to replace the 3rd occurence of 'cat' by 'dog'The first run until 'cat' is found, then the second one, and the third one before the 3rd 'cat' are 'protected'$str = "the first is a cat, the second is a cat, the third is a cat, the fourth is a cat" $res = StringRegExpReplace ($str, '^(?:.*?\Kcat){3}' , 'dog' ) Msgbox(0,"", $res)Gewurtz is pretty good, though my preference goes to the Riesling which is drier (personal taste) iamtheky 1
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