1

I have a page that displays the user's IP address, I can't edit the code as it is encoded, so I'm just making edits in smarty templates. I'm trying to using regex to hide the user's IP address that shown on that page.

Here is the code I have but its not working:

$('div#container').text(function (i, t) {
    return t.replace(new RegExp("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b", 'gi'), '');
})

I tried more that one regex format found in this question.

If I directly inserted my IP, it works and hide it, however if I used regex format instead, it won't work.

I'd greatly appreciate it if anyone could shed some light on this. Thank you so much.

Community
  • 1
  • 1
Mina Hafzalla
  • 2,681
  • 9
  • 30
  • 44
  • 1
    How about `$('div#ipaddress').hide()` ? – Daniel W. Jun 17 '15 at 20:25
  • what is the question? – Alex Jun 17 '15 at 20:25
  • @DanFromGermany That was a silly sample from me, sorry I didn't clarify, I edited the question. The IP Address is within the container, so I need to only hide it not the entire container. – Mina Hafzalla Jun 17 '15 at 20:28
  • So as suggested by @DanFromGermany can you add the ip address inside a `` and then simply call `$('span#ipaddress')/hide()` ? – bhantol Jun 17 '15 at 20:36
  • On another note - hiding it this way won't really hide it from a tech savvy user. So you may want to rethink about this hiding approach. – bhantol Jun 17 '15 at 20:37
  • @bhantol He can't alter the code. For whatever reason. – Daniel W. Jun 17 '15 at 20:38
  • If @JFallz is able to add the jQuery code `.text()` then adding `.hide()` should be possible. However in templates are typically HTML fragments and so adding JavaScript in that way won't work. @JFallz what are `smarty templates` that you mentioned ? – bhantol Jun 17 '15 at 20:47

1 Answers1

2

Try one of these

t.replace(new RegExp("\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b", 'gi'), ' ')

t.replace( /\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/gi, ' ')