SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Regexp replace
-
Jul 13, 2007, 07:32 #1
- Join Date
- Aug 2006
- Posts
- 36
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Regexp replace
Hi,
I am really stuck with regexp replace.
I want to replace a string after checking it is valid by passing the values to a function.
The string is '<img width="300" height="300">'
Code:var text = '<img width=300 height=300>'; text = text.replace(/<img width\=(.*?) height\=(.*?)>/gi, check_img($1, $2));
This same method works in PHP by the e Modifier but not in JS.
Please Help.
-
Jul 13, 2007, 07:49 #2
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In javascript, to execute on replace, the second parameter must be a function, e.g.
Code:function check_img(tag, widht, height) { //........................ } text = text.replace(/<img width\=(.*?) height\=(.*?)>/gi, check_img);
-
Jul 13, 2007, 08:03 #3
- Join Date
- Aug 2006
- Posts
- 36
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
But how to pass $1 and $2 to this function.
In your example it is not passed to the function.
EDIT:
I get it now the $1...$9 are passed directly into the function parameters
Thanks guysLast edited by helpmeinphp; Jul 13, 2007 at 08:11. Reason: Got that
Bookmarks