Здравствуйте, я хотел бы создать функцию javascript, которая бы возвращала 7 слов до и после математики для конкретного ключевого слова
Я пытался сделать следующее:
function myFunction(text) {
b=text.match("(?:[a-zA-Z'-]+[^a-zA-Z'-]+){0,7}"+text+"(?:[^a-zA-Z'-]+[a-zA-Z'-]+){0,7}");
return b;
Однако, когда я ищу вмой текст "создать" я просто получил:
create
Мой желаемый результат будет:
the Community, and view patterns you create or favorite in My Patterns. Explore results
Мой полный код выглядит следующим образом, с моей соответствующей строкой под названием Текст, поэтому я бынравится ценить поддержку, чтобы преодолеть эту задачу.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var Text='RegExr was created by gskinner.com, and is proudly hosted by Media Temple. Edit the Expression & Text to see matches. Roll over matches or the expression for details. PCRE & Javascript flavors of RegEx are supported. The side bar includes a Cheatsheet, full Reference, and Help. You can also Save & Share with the Community, and view patterns you create or favorite in My Patterns. Explore results with the Tools below. Replace & List output custom results. Details lists capture groups. Explain describes your expression in plain English.'
function myFunction(text) {
b=text.match("(?:[a-zA-Z'-]+[^a-zA-Z'-]+){0,7}"+text+"(?:[^a-zA-Z'-]+[a-zA-Z'-]+){0,7}");
return b;
}
document.getElementById("demo").innerHTML = myFunction("create");
</script>
</body>
</html>