Rahul
Rahul

Reputation: 11560

How to accomplish repetitive regex replace

I want to replace following in single stroke.

With regEx_
 .Global = True
 .MultiLine = True
 .IgnoreCase = True    
.Pattern = "xxxxxx(.*)[\r\n]+xxxxxx"
TextLine = regEx_.replace(TextLine, "xxxxxx$1,")
.Pattern = "xxxxxx(.*)[\r\n]+xxxxxx"
TextLine = regEx_.replace(TextLine, "xxxxxx$1,")
.Pattern = "xxxxxx(.*)[\r\n]+xxxxxx"
TextLine = regEx_.replace(TextLine, "xxxxxx$1,")
.Pattern = "xxxxxx(.*)[\r\n]+xxxxxx"
TextLine = regEx_.replace(TextLine, "xxxxxx$1,")
End With

The Ides is to delimit the lines

For example:

From This,

xxxxxx1
xxxxxx2
xxxxxx3
xxxxxx4

To this.

xxxxxx1,2,3,4

I want to repeat until no match remains to be found.

EDIT

Lines are not exclusive in string but a part of strin like

yzyzyz#
xxxxxx1
xxxxxx2
xxxxxx3
xxxxxx4
yzyzyz*
xxxxxx1
xxxxxx2

Upvotes: 0

Views: 140

Answers (1)

zessx
zessx

Reputation: 68810

You could use something like the global flag:

input.replace(/[\r\n]+xxxxxx/g, ',')
// output: xxxxxx1,2,3,4

Using VBScript, it would looks like this:

Dim TextLine, regEx_
TextLine = "xxxxxx1" & VbCrLf & _
           "xxxxxx2" & VbCrLf & _
           "xxxxxx3" & VbCrLf & _
           "xxxxxx4"

Set regEx_ = new regexp
With regEx_
 .Global = True
 .MultiLine = True
 .IgnoreCase = True
 .Pattern = "[\r\n]+xxxxxx"
TextLine = regEx_.replace(TextLine, ",")
End With

Upvotes: 1

Related Questions