On Mar 7, 2020, at 5:12 AM, Roland Küffner wrote:
>
> It is a little confusing or unintuitive(*), that the pattern FINDS both
> instances but only CAPTURES the last one. But once you understand the
> mechanism it is a lot easier to construct working patterns.
I think it may make more sense if
Fletcher, thanks for the very helpfull link. To summarize that discussion:
the {2} tells the capture group to look twice for it‘s pattern, but the
capture group only saves the last instance it found. Putting the whole
search term into another capture group should give you the desired result
(as
There's a good discussion at the following URL but it occurs because the
regular expression is evaluated as a state machine. Here the capturing group
itself is repeated by the {2}. The first match is discarded when it sees the
second match and that's what you see in the results.
When using the Pattern Playground, in the search pattern's capture group #1
(see below), why is `847-` appearing rather than `717-`?
Search pattern: (\d{3}[.-]?){2}
Source text: 717-847-8015
Capture Groups:
#0: 717-847-
#1: 847-
--
This is the BBEdit Talk public discussion group. If you have
It lets you use parenthesis without creating a capture group.
If you’re looking for ‘def’ in this line:
abc def
Then you could use:
(abc) (def)
But your ‘def’ would end up in capture group 2.
If you instead use:
(?:abc) (def)
Then ‘def’ will be in capture group 1.
fletcher,
Your change addressed my question. If you could explain what `?:` does I
would much appreciate it.
Howard
On Sunday, March 1, 2020 at 11:00:58 AM UTC-5, flet...@cumuli.com wrote:
>
> I think the problem is that the {2} calling for a repetition of the
> previous pattern is outside
I think the problem is that the {2} calling for a repetition of the previous
pattern is outside the parentheses which signal the capture. You can use a
non-capturing group (?: ) to group patterns without creating another capture.
And then wrap the entire new expression with the repetition in
In the Pattern Playground, I am running this pattern ->
*(\d{3}[-.]){2}(\d{4})*
with the data shown below.
Here is my input data:
123.179-9876
123.456-9876
123-456-9870
126-456-987
1257-456--0
123-456
12345
Three capture groups are shown in the *Capture groups* box.
[image: Screen Shot