Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 25.07.2019, 00:37
Аспирант
Отправить личное сообщение для flyte Посмотреть профиль Найти все сообщения от flyte
 
Регистрация: 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-й точки, но после первого предложения может быть троеточие и такой вариант сразу отпал
Ответить с цитированием
  #2 (permalink)  
Старый 25.07.2019, 07:51
Аватар для ksa
ksa ksa вне форума
CacheVar
Отправить личное сообщение для ksa Посмотреть профиль Найти все сообщения от ksa
 
Регистрация: 19.08.2010
Сообщений: 14,123

Сообщение от 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]);
Ответить с цитированием
  #3 (permalink)  
Старый 25.07.2019, 07:56
Аватар для ksa
ksa ksa вне форума
CacheVar
Отправить личное сообщение для ksa Посмотреть профиль Найти все сообщения от ksa
 
Регистрация: 19.08.2010
Сообщений: 14,123

Для других вариантов окончания предложения...
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]);
Ответить с цитированием
  #4 (permalink)  
Старый 25.07.2019, 17:49
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 4,662

flyte, ksa, в английском точка еще используется в дробных числах.
Ответить с цитированием
  #5 (permalink)  
Старый 26.07.2019, 07:28
Аватар для ksa
ksa ksa вне форума
CacheVar
Отправить личное сообщение для ksa Посмотреть профиль Найти все сообщения от ksa
 
Регистрация: 19.08.2010
Сообщений: 14,123

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.
Ответить с цитированием
  #6 (permalink)  
Старый 29.07.2019, 13:16
Аспирант
Отправить личное сообщение для flyte Посмотреть профиль Найти все сообщения от flyte
 
Регистрация: 23.09.2014
Сообщений: 72

ksa,
спасибо большое
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
регулярные выражения remember_me Общие вопросы Javascript 2 26.12.2013 14:56
Составить регулярные выражения ($) Zero Tolerance Общие вопросы Javascript 10 19.11.2013 13:14
Регулярные выражения для javascript qwert_ukg Общие вопросы Javascript 3 20.04.2012 13:45
нежадные регулярные выражения KOLANICH Общие вопросы Javascript 2 12.12.2010 01:08
Функции поиска и замены строк или регулярные выражения? Armen Общие вопросы Javascript 1 01.01.2010 12:35