I have tried a lot of combinations but have not been able to do this replace.
Each line of the text file is variable in length and ends with an amount that has 2 decimal places and is followed by "\par". Examples: " 158.00\par" and " 9.53\par"
Note the amounts can be a variable number of whole dollars.
I want to replace the space in front of the the first whole dollar digit with this character "~" example: "~158.00\par" and "~9.53\par"
Thanks for any help...
need help with complex replace
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
"Posix" syntax (TextPad uses the term incorrectly) doesn't change the expressive power of TextPad's regular expressions: it just changes the way that backslashes are used. In most cases regular expressions are more readable in this syntax than in the default syntax.
_([0-9]+\.[0-9]{2}\\par) [replace the underscore with a space] matches
where
[0-9]+ matches
and
[0-9]{2} matches
We replace the matched text with
~\1
which is composed of
_([0-9]+\.[0-9]{2}\\par) [replace the underscore with a space] matches
Code: Select all
_ [the underscore is really a space] a space
( (start of captured text number 1)
[0-9]+ a non-empty sequence of digits (see below)
\. a dot
[0-9]{2} two digits (see below)
\\ a backslash
par the literal text "par"
) (end of captured text number 1)
[0-9]+ matches
Code: Select all
[0-9] any digit
+ ... any non-zero number of times
[0-9]{2} matches
Code: Select all
[0-9] any digit
{2} ... two times
~\1
which is composed of
Code: Select all
~ a tilde
\1 captured text number 1
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
Whatever would have been matched by a second parenthesised part of the regex if there had been one.
If part of a regex is parenthesised, whatever text that part matches is captured for use in the replacement expression. The parentheses are numbered from left to right by the position of their open-parenthesis symbols. In the replacement expression, \1 represents what was captured by the first parenthesised expression, \2 represents what was captured by the second, and so on.
If part of a regex is parenthesised, whatever text that part matches is captured for use in the replacement expression. The parentheses are numbered from left to right by the position of their open-parenthesis symbols. In the replacement expression, \1 represents what was captured by the first parenthesised expression, \2 represents what was captured by the second, and so on.