Попробуйте это: ^.*?-.*?-(.*?\..*?)\.
Объяснение:
^ : [^] represents the beginning of the string
.*?- : [.] is any character except line breaks,
[*] matches 0 or more (aka optional),
[?] makes it lazy meaning it will match as few characters as possible.
[-] matches a literal '-' character
.*?-.*?- : doing this pattern twice will match the following: '--', 'ANY-THING-', '-ANYTHING-',
'TWO-DASHES-', 'TWODASHES--', etc.
(.*?\..*?)\. : ( ) wrapping a pattern makes it a capture group used to easily pull what you need
[.*?] - same as above (lazy, optional character(s))
[\.] - escaped literal '.' character (#1)
[.*?] - same as above (lazy, optional character(s)) again
[\.] - escaped literal '.' character (#2) - notice it's outside our capture group
to make it non-inclusive
Используя это, желаемая строка --.some.thing.
вернет что-либо от первой точки ко второму экземпляру точки,только захват первой точкиСтроки сопоставляются только в том случае, если есть две черты и две или более точек после черточек.Вот несколько тестов:
this-is-a.test.sentence -- matches // group 1: 'a.test'
any-thing-some.thing.cool -- matches // group 1: 'some.thing'
anything-some.thing.cool -- doesn't match because there is only one dash
any-thing-some.thingcool -- doesn't match because there is only one dot
any.thing-some.thing-cool -- doesn't match because the dashes and dots are out of order.