Replace inside a regexp

Just starting out? Need help? Post your questions and find answers here.
loulou2522
Enthusiast
Enthusiast
Posts: 501
Joined: Tue Oct 14, 2014 12:09 pm

Replace inside a regexp

Post by loulou2522 »

here is My regexp problem
Texte= "Bonjour"+#crlf$+"Bonsoir"
I want to insert "ino" beside "on"
example of result Binoonjour+ ##Crlf$+"Binoonsoir"
How ca i do ?
Thanks in advance
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Replace inside a regexp

Post by falsam »

Code: Select all

Texte$ = "Bonjour" + " et " + "Bonsoir"

If CreateRegularExpression(0, "on")
  Result$ = ReplaceRegularExpression(0,  Texte$, "inoon")
Else
  Debug RegularExpressionError()
EndIf

Debug Result$
Debug wrote:Binoonjour et Binoonsoir
Fonctionne bien sur avec Texte$ = "Bonjour"+ #CRLF$ +"Bonsoir" :wink:
Last edited by falsam on Tue Mar 28, 2017 10:16 am, edited 1 time in total.

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Replace inside a regexp

Post by Marc56us »

loulou2522 wrote:here is My regexp problem
Texte= "Bonjour"+#crlf$+"Bonsoir"
I want to insert "ino" beside "on"
example of result Binoonjour+ ##Crlf$+"Binoonsoir"
(in your request sample, not beside, but before)

Code: Select all

--- Source
Bonjour
Bonsoir 

--- Expected
Binoonjour
Binoonsoir

--- Search for
^(B)(onjour\r\nB)(onsoir)$

--- Replace with
$1ino$2ino$3

--- Result
Binoonjour   
Binoonsoir   
But, no need RegEx

Code: Select all

EnableExplicit

Define Texte1.s = "Bonjour" + #CRLF$ + "Bonsoir"

Debug "--- Before " + #CRLF$ + Texte1 + #CRLF$

Define Texte2.s = ReplaceString(Texte1, "on", "inoon")

Debug "--- After " + #CRLF$ + Texte2 + #CRLF$

; --- Before 
; Bonjour
; Bonsoir
; 
; --- After 
; Binoonjour
; Binoonsoir
:wink:
Post Reply