Jump to content

Recommended Posts

  • Moderators
Posted

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

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

 

Posted

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)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

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

Posted

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.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

Melba,
Your guess is right  :)
\K is a pretty nice thing. In a SRER all chars mentioned in the pattern before \K are 'protected' indeed

A 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)  :D

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
  • Recently Browsing   0 members

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