Quantcast
Channel: CodeProject Latest postings for Regular Expressions
Viewing all articles
Browse latest Browse all 224

How to retain characters preceding a match?

$
0
0
I'm using an application called Panorama X (see provue.com) which has a function, RegExReplace, which, in a block of text, replaces every occurrence of a string defined by a regular expression with a different string. For example,

RegExReplace(TextBlock,"^[;]","//")

will search a block of text called TextBlock for all lines beginning with a semi-colon and will replace the semi-colon with two slashes.

In some lines, the ";" is preceded by a number of spaces but I still want to change it. The only way I've been able to do this is to copy the characters before the ";" and do this:

RegExReplace(TextBlock,"^[ ]+[;]",<preceding spaces=""> +"//")

which is a little clumsy.

Is there a better way to do it? I'm very new to RegEx.

michael

Viewing all articles
Browse latest Browse all 224

Trending Articles