Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]wyrażenia regulane
query
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 3.09.2014

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


Witam

Mam fragment
  1. "jakis tekst my_function('arg1,arg2') jakis tekst"

Chcę pobrać wszystkie argumenty funkcji 'my_function' podając tylko jeden argument tej funkcji.


Niestety poniższy kod nie działa a powinien zwrócić wartość 'arg1,arg2'
  1. var string = "jakis tekst my_function('arg1,arg2') jakis tekst";
  2. var regex = /my_function\(\'(arg2)\'\)/;
  3. console.log( string.match(regex));


Ten post edytował query 3.09.2014, 08:59:56
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
golabow
post
Post #2





Grupa: Zarejestrowani
Postów: 53
Pomógł: 17
Dołączył: 4.07.2014

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


Może to Ci pomoże:

  1. <script>
  2. var string = "jakis tekst my_function('arg1,arg2,argument23') jakis tekst";
  3. var regex = /my_function\((.*?)\)/;
  4. console.log( string.match(regex)[1]);
  5. </script>


Ten post edytował golabow 3.09.2014, 10:24:51
Go to the top of the page
+Quote Post
query
post
Post #3





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 3.09.2014

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


Cytat(golabow @ 3.09.2014, 11:21:14 ) *
Może to Ci pomoże:

  1. <script>
  2. var string = "jakis tekst my_function('arg1,arg2,argument23') jakis tekst";
  3. var regex = /my_function\((.*?)\)/;
  4. console.log( string.match(regex)[1]);
  5. </script>



Dzięki to działa dobrze. Problem w tym ze ja tych funkcji mam wiele z różnym argumentami.
Jak z poniższego przykładu pobrać wartość 'arg100,arg200' (IMG:style_emoticons/default/questionmark.gif)

  1. <script>
  2. var string = "jakis tekst my_function('arg1,arg2,argument23') jakis tekst my_function('arg100,arg200')";
  3. var regex = /my_function\((.*?)\)/;
  4. console.log( string.match(regex)[1]);
  5. </script>

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: 18.10.2025 - 06:38