Topic: Regex Help.. not working :( Pages that link to <a href="https://ozoneasylum.com/backlink?for=27777" title="Pages that link to Topic: Regex Help.. not working :(" rel="nofollow" >Topic: Regex Help.. not working :(\

 
Author Thread
H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

IP logged posted posted 04-12-2006 06:55 Edit Quote

Hey folks.

Basically i want a regex for javascript that will replace any html tags in a string with their lowercase versions.

So far i have

code:
clipHtml = clipHtml.replace(/(<\/?[^>]*>)/g, '$1'.toLowerCase())



The first part of the expression is correct and matches any tags, but the second part doesnt seem to be working. Most sites i've seen say to use $1 or \$1 or \1 or various other things to put the matched express into the replace-with part of the javascript expression.


Any ideas?

Thanks.

(Edited by H][RO on 04-12-2006 07:18)

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 04-12-2006 07:55 Edit Quote

Hm... As far as I see it, you're lowercasing '$1',
which is only afterwards expanded to the full string.

So... try defining a function lowerThat ( str)
return str.toLowerCase()

and pass that to replace.
That way, you'll actually pass in a function, instead of a string, and that's what you want.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

IP logged posted posted 04-12-2006 10:23 Edit Quote

mmm, yeh i ended up just doing

code:
clipHtml = clipHtml.replace(/(<\/?[^>]*>)/g, function(x){return x.toLowerCase()})




i thought it should have worked even if its expanding it afterwards, it wasnt including the string method in the result or anything.

Oh well

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 04-12-2006 17:47 Edit Quote

Oh, it was. But '$1' toLowerCase() is still just '$1'.
If you had replaced with "ABCD".toLowerCase() you would have seen it.

Remember functions are being evaluated from the inner to the outer.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu