Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]text.match zwraca za dużo
Warmix
post
Post #1





Grupa: Zarejestrowani
Postów: 173
Pomógł: 0
Dołączył: 13.06.2011

Ostrzeżenie: (0%)
-----


Cytat
var str2 = document.getElementById("textarea").value;
str2 = str2.match(/test1(.*?)test2/g);

document.getElementById("p3").innerHTML = str2;


Czemu taki kod zwraca mi wartość:
Cytat
test1 tutaj jakis test test2


Chciałbym, aby zwracał:
Cytat
tutaj jakis test
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kapslokk
post
Post #2





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


[JAVASCRIPT] pobierz, plaintext
  1. var str2 = document.getElementById("textarea").value;
  2.  
  3. var regex = /test1(.*?)test2/g;
  4. str2 = regex.exec(str2)
  5.  
  6. document.getElementById("p3").innerHTML = str2[1];
[JAVASCRIPT] pobierz, plaintext


Ten post edytował kapslokk 15.09.2016, 08:58:02
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 27.09.2025 - 16:19