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%)
-----


@nospor - Teraz to i sam do tego doszedłem (IMG:style_emoticons/default/biggrin.gif)

@Warmix
.exec wielokrotnie odpalany bedzie zwracal kolejne wyniki:

[JAVASCRIPT] pobierz, plaintext
  1. var str = "test1 111 test2 test1 tutaj jakis test test2 test1 tutaj jakis test test2";
  2. var regex = /test1(.*?)test2/g;
  3. var res;
  4. res = regex.exec(str)
  5. console.log(res)
  6. res = regex.exec(str)
  7. console.log(res)
  8. res = regex.exec(str)
  9. console.log(res)
  10. res = regex.exec(str)
  11. console.log(res)
[JAVASCRIPT] pobierz, plaintext


Mozesz odpalić go w pętli

Ten post edytował kapslokk 15.09.2016, 09:26:10
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: 1.10.2025 - 13:37