Hi,
I'm trying to write something and I almost have it... almost...
What I have:
1. This needs to be bolded. The rest does not. There may be several. Sentences, that is.
What I need to end up
1. <p><b>This needs to be bolded.</b> The rest does not. There may be several. Sentences, that is.</p>
Searching: ([0-9]+)\. (.*\.) (.*)
replacing with: \1. <p><b>\2</b> \3</p>
got me this:
1. <p><b>This needs to be bolded. The rest does not. There may be several.</b> Sentences, that is.</p>
So it found the LAST period-space, not the first one.
When I tried the search using this: ([0-9]+)\. (.*)\. (.*)
I still got this:
1. <p><b>This needs to be bolded. The rest does not. There may be several</b> Sentences, that is.</p>
So I wondered, how do I get it to STOP at the FIRST period?
([0-9]+)\. ([.*.])(.*)
and
([0-9]+)\. ([.*\.])(.*)
Don't 'find' it. I thought adding the period in brackets after the 'find all' .* would say "go to that char and stop" but apparently not, and 'escaping' it didn't help.
Would appreciate any insight. Must be something obvious I'm missing.
PJ
The first rather than the last of something
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
More powerful regex recognisers than TextPad's support non-greedy repetition operators that match as little as possible rather than as much as possible. Using these recognisers, in the regex
.*?\.
(which will not work in TextPad) the subexpression .*? would match the shortest string that allowed the expression as a whole to match; thus it would match up to the first dot.
But in your case, since there is just one character (dot), rather than a sequence of characters, that should not be matched by the subexpression, you can simply exclude it from the repetition:
[^.]*
So this does what you want:
([0-9]+)\. ([^.]*\.) (.*)
.*?\.
(which will not work in TextPad) the subexpression .*? would match the shortest string that allowed the expression as a whole to match; thus it would match up to the first dot.
But in your case, since there is just one character (dot), rather than a sequence of characters, that should not be matched by the subexpression, you can simply exclude it from the repetition:
[^.]*
So this does what you want:
([0-9]+)\. ([^.]*\.) (.*)