--- Sven E Olsson <[EMAIL PROTECTED]> wrote:
> Now I have this problem, I have a replaceAll function, but it
> do NOT
> replace the first match ..
> There is NO wholeword or casesesitive .....
The RegEx class keeps an internal pointer so that you can call it
multiple times and have each new search pick up where the last
one left off. If you call rg.search or rg.replace with no
arguments, it resumes its searching/replacing wherever the last
search/replace left off.
In your code, you call rg.search first. This finds the first
match, and sets the placeholder immediately after the match. When
you call rg.replace, it does a replaceAll beginning immediately
after the first match, so the first one does not get replaced.
You can fix this by either calling rg.replace(EditField1.Text) at
the beginning, instead of calling rg.search, or you can add
(EditField1.Text) as the argument to rg.replace inside the "If
searchResult <> nil then" block.
> dim rg as RegEx
> dim SearchResult As RegExMatch
> rg = New RegEx
> rg.SearchPattern = EditField2.text
> rg.ReplacementPattern = EditField3.Text
>
> rg.Options.ReplaceAllMatches = true // If this is set to
> FALSE
> only the second Match is replaced
> SearchResult = rg.Search(EditField1.text)
// or call SearchResult = rg.Replace(EditField1.Text)
> if SearchResult <> nil then
> EditField1.Text = ""
> EditField1.AppendText rg.Replace
or call EditField1.AppendText
rg.Replace(EditField1.Text)
> end if
Use either of the above fixes and it should work.
Mark Nutter
Quick and easy regex creation and debugging!
http://www.bucktailsoftware.com/products/regexplorer/
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>