RE question

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Camilo Arango

RE question

Post by Camilo Arango »

Hello. I need to build a RE that matches the following: Format(<here goes anything>)
For Example:
Format(25.000)
Format($450.00)
Format(25)
Format(0)

I need to replace it the following way:
Format(<here goes anything>, 1)

Any help would be deeply appreciated.


Camilo Arango
Camilo Arango

Re: RE question

Post by Camilo Arango »

Hello. I have just found the answer searching another similar problem in this Forum. Im just publishing it here in case someone could need it:

Find: Format(<here goes anything>)
The RE "Format(.*)" matches anything between the parenthesis.


bye

Camilo Arango
Jeff Epstein

Re: RE question

Post by Jeff Epstein »

While "Format(.*)" would probably serve you well 95% of the time..

To be more precise, you might want to find anything *except* parethesis:

Find: Format([^()]+)

Note the difference between these two search patterns when searching on this line of text:

--------------------------------------------------------
Format(blablabla) (blablabla)
--------------------------------------------------------

AND...If you're positive that there will be at least one character inside the parenthesis, then use plus (meaning one or more). Otherwise, if it's possible that there will be *no* characters between the parenthesis, then use asterisk (meaning zero or more):

Find: Format([^()]*)
Jeff Epstein

Re: RE question

Post by Jeff Epstein »

Oh, but we still didn't answer your question.

To search AND REPLACE for what you want, use this:

Find What: \(Format([^()]+\))
Replace With: \1, 1)
Regular Expression: [X]
......other settings don't matter......


Note that, in Find What, "Format([^()]+" is surrounded by "\(" and "\)". This is designated, in Replace With, by "\1".

Look in the help documentation regarding Regular Expressions (RE) and Replacement Expressions for information. Once you get the hang of regular expressions, it's very cool.
Post Reply