MyBB Community Forums

Full Version: more regex help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to replace some text using preg_replace but only if it does not start with http/https/ftp/ftps

basically if a domain or IP is present in the HTML I want to replace it, but not any cases of the domain or IP being part of an actual URL.

can anyone help with this? i'd rather not be forced to brute force it by replacing the http parts with a placeholder and then replace the other cases of the text and then replace the palceholder with the http bit again
How's this?

^((?!http|ftp).)*$

If the string starts with "http" or "ftp" at all, it will not be matched. Tested here: http://gskinner.com/RegExr/
that is close but not doing what I need.

search:
asdf.com

replace:
zxcv.com

except when:
http://asdf.com
ftp://asdf.com

i want to replace a given domain/ip in the browser output, but let underlying links to the domain/ip remain intact.

<script src='http://asdf.com/my.js'>
<strong>asdf.com</strong>

to become

<script src='http://asdf.com/my.js'>
<strong>zxcv.com</strong>

tags and such only as examples, it needs to be any reference except those in a URL
Why not just use parse_url? I believe it returns the prefix, domain and any query string. Then you could just str_replace the domain.
got it figured out, thanks for the link to that site

^((?<!http|https|ftp|ftps)\://asdf\.com)

its using pre_output_page(), so i want to make it as fast as possible (I already limit it to the pages and actions I need)
Ah, glad you got it sorted!
actually, its not working. my test text only grabbed the raw text, notthe url part (first match). when i swapped it, it still grabbed the first match but it was the url one....


aaarrrgghhhhh!
Could you possibly give an example of what you're trying to match and replace to? Might help me understand exactly what you want a bit better Smile
this one is working now. the problem was partly that since since I could not copy paste from it, so i was always pasting the incorrect regex that was off by 1-2 items.

this one works:
 ((?<![http|https|ftp|ftps]\://)asdf\.com)

basically I have a plugin request to mask IPs for specified users, but in my testing on my localhost, it breaks it all since I am using an IP as my bburl. so i want to exclude the Ip when it is part of the head, script, links, etc, and only mask the ip being output as part of the browser display, such as in getip() or WOL, etc.