25.07.2019, 00:37
|
Аспирант
|
|
Регистрация: 23.09.2014
Сообщений: 72
|
|
Выбрать предложение до второй точки. Регулярные выражения.
Доброго времени суток. Помогите составить регулярное выражения для выбора первых двух предложений из текста.
English singer, songwriter, guitarist, record producer, and actor... He attended the Academy of Contemporary Music in Guildford as an undergraduate from the age of 18 in 2009. In early 2011, Sheeran independently released the extended play, No. 5 Collaborations Project. After signing with Asylum Records, his debut album, +, was released in September 2011. It topped the UK and Australian charts, reached number five in the US, and has since been certified seven-times platinum in the UK. The album contains the single "The A Team", which earned him the Ivor Novello Award for Best Song Musically and Lyrically...
Я думал выбрать до 2-й точки, но после первого предложения может быть троеточие и такой вариант сразу отпал
|
|
25.07.2019, 07:51
|
|
CacheVar
|
|
Регистрация: 19.08.2010
Сообщений: 14,217
|
|
Сообщение от flyte
|
составить регулярное выражения для выбора первых двух предложений из текста
|
Как вариант...
var txt='English singer, songwriter, guitarist, record producer, and actor... ';
txt+='He attended the Academy of Contemporary Music in Guildford as an undergraduate ';
txt+='from the age of 18 in 2009. In early 2011, Sheeran independently released ';
txt+='the extended play, No. 5 Collaborations Project. After signing with Asylum ';
txt+='Records, his debut album, +, was released in September 2011. It topped the ';
txt+='UK and Australian charts, reached number five in the US, and has since been ';
txt+='certified seven-times platinum in the UK. The album contains the single ';
txt+='"The A Team", which earned him the Ivor Novello Award for Best Song Musically ';
txt+='and Lyrically...';
alert(txt.match(/([^\.]+\.{1,3}\s?){1,2}/)[0]);
|
|
25.07.2019, 07:56
|
|
CacheVar
|
|
Регистрация: 19.08.2010
Сообщений: 14,217
|
|
Для других вариантов окончания предложения...
var txt='English singer, songwriter, guitarist, record producer, and actor... ';
txt+='He attended the Academy of Contemporary Music in Guildford as an undergraduate ';
txt+='from the age of 18 in 2009! In early 2011, Sheeran independently released ';
txt+='the extended play, No. 5 Collaborations Project. After signing with Asylum ';
txt+='Records, his debut album, +, was released in September 2011. It topped the ';
txt+='UK and Australian charts, reached number five in the US, and has since been ';
txt+='certified seven-times platinum in the UK. The album contains the single ';
txt+='"The A Team", which earned him the Ivor Novello Award for Best Song Musically ';
txt+='and Lyrically...';
alert(txt.match(/([^\.!?]+([!?]|(\.{1,3}))\s?){1,2}/)[0]);
|
|
26.07.2019, 07:28
|
|
CacheVar
|
|
Регистрация: 19.08.2010
Сообщений: 14,217
|
|
Rise, я даже не расстроился...
var txt='English singer, songwriter, guitarist, record producer, and actor... ';
txt+='He attended the Academy of Contemporary Music in Guildford as an undergraduate ';
txt+='from the age of 18.21 in 2009! In early 2011, Sheeran independently released ';
txt+='the extended play, No. 5 Collaborations Project. After signing with Asylum ';
txt+='Records, his debut album, +, was released in September 2011. It topped the ';
txt+='UK and Australian charts, reached number five in the US, and has since been ';
txt+='certified seven-times platinum in the UK. The album contains the single ';
txt+='"The A Team", which earned him the Ivor Novello Award for Best Song Musically ';
txt+='and Lyrically...';
txt=txt.replace(/(\d*)\.(\d+)/g,'$1,$2');
txt=txt.match(/([^\.!?]+([!?]|(\.{1,3}))\s?){1,2}/)[0];
txt=txt.replace(/(\d*)\,(\d+)/g,'$1.$2');
alert(txt);
Последний раз редактировалось ksa, 26.07.2019 в 07:37.
|
|
29.07.2019, 13:16
|
Аспирант
|
|
Регистрация: 23.09.2014
Сообщений: 72
|
|
ksa,
спасибо большое
|
|
|
|