I want to convert lines like these
05 Baroque 117
06 Female Vocals 240
07 Christmas 128
08 Conniff 85
09 Easy, Ambient,etc 184
10 Movies-Musicals-etc 410
into
05 Baroque #1 (117)
06 Female Vocals #1 (240)
07 Christmas #1 (128)
08 Conniff #1 (85)
etc
IOW, add the fixed string '#1', put the 2 or 3 digit number into regular brackets, and move it to the end.
I suspect my main problem is how to specify say two or three digits, or any number come to that. I've seen the suffix '*' used, but that does not work for me.
Struggling with this one, especially ''''''''muliple digits''''''''
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
I re-discovered the '+' suffix (I'd been placing braces around it) but this
Find: ([0-9]{2})(.*)([0-9]+)
Replace with: \1\2\(\3\)
delivered this
05 Baroque 11(7)
06 Female Vocals 24(0)
07 Christmas 12(8) that's '8' in brackets, not an emoticon as it displays here!
08 Conniff 18(5)
09 Easy, Ambient,etc 18(4)
10 Movies-Musicals-etc 41(0)
etc
and I don't see my mistake?
Find: ([0-9]{2})(.*)([0-9]+)
Replace with: \1\2\(\3\)
delivered this
05 Baroque 11(7)
06 Female Vocals 24(0)
07 Christmas 12(8) that's '8' in brackets, not an emoticon as it displays here!
08 Conniff 18(5)
09 Easy, Ambient,etc 18(4)
10 Movies-Musicals-etc 41(0)
etc
and I don't see my mistake?
-
- Posts: 2457
- Joined: Sun Mar 02, 2003 9:22 pm
Thanks, that works fine.
I follow the Find what, now that I see '\d' as a neat alternative to [0-9]. (Is the latter now not generally used?)
But can you explain the Replace with please?
Why two uses of '$'? How can two things be 'at the end of a line'? Or is '$' confusingly an alternative to '\'?
And is the '^' redundant? (It works OK without.) How is it to be interpreted before '( )?
Can you recommend a compact summary of all these syntax rules please? I suspect my documentation is incomplete.
I follow the Find what, now that I see '\d' as a neat alternative to [0-9]. (Is the latter now not generally used?)
But can you explain the Replace with please?
Why two uses of '$'? How can two things be 'at the end of a line'? Or is '$' confusingly an alternative to '\'?
And is the '^' redundant? (It works OK without.) How is it to be interpreted before '( )?
Can you recommend a compact summary of all these syntax rules please? I suspect my documentation is incomplete.
-
- Posts: 2457
- Joined: Sun Mar 02, 2003 9:22 pm
[0-9] matches only ASCII digits (the Hindu-Arabic numerals 0..9). \d matches any digit in any script, including non-ASCII ones (such as Arabic-Indic ٠..٩, Bengali ০..৯, Lao �..໙). If the text being searched is ASCII, [0-9] and \d are equivalent.
A replacement expression is not a regular expression. They have different purposes and they are interpreted differently. In a replacement expression $1 is equivalent to \1; it represents whatever was captured by the first capturing group in the regular expression.
Caret (^) is an anchor: it matches at a certain position without matching any characters. ^ matches at the beginning of a line.
There are many regex tutorials on the Web, but I am not familiar with them. TextPad has its own summary in its help. Look under
Reference Information | Regular Expressions and
Reference Information | Replacement Format Strings.
A replacement expression is not a regular expression. They have different purposes and they are interpreted differently. In a replacement expression $1 is equivalent to \1; it represents whatever was captured by the first capturing group in the regular expression.
Caret (^) is an anchor: it matches at a certain position without matching any characters. ^ matches at the beginning of a line.
There are many regex tutorials on the Web, but I am not familiar with them. TextPad has its own summary in its help. Look under
Reference Information | Regular Expressions and
Reference Information | Replacement Format Strings.