0

Using regex javascript or Jquery, how do i select a lone character or in the body element? We have noticed that there's a random "s" at the bottom of our site, after the footer. We have no idea where it came from -it's really bizarre because it's in the body element, but it's not tied to any child element. it's just floating there in between some script tags.

screenshot of the 's' after the footer

screenshot of the 's' after the footer


here is the 's' in the DOM in between scripts

here is the 's' in the DOM in between scripts


It might be from a plugin - but in the meantime, we were hoping we could hide this until we find the culprit.

I'm trying to select the element first with this in the console, but I've had no success.

jQuery('body').filter( function(){ return /([s]$)/g.test( jQuery(this).text() ) } )

However, I can't select this element.. does anyone know how I can do this? Thanks so much

ssc-hrep3
  • 15,024
  • 7
  • 48
  • 87
  • Maybe your `s` character was added by adding a new script tag, and then saving with CTRL + S? – ssc-hrep3 Apr 25 '19 at 22:17
  • https://stackoverflow.com/questions/298750/how-do-i-select-text-nodes-with-jquery – ssc-hrep3 Apr 25 '19 at 22:19
  • @ssc-hrep3 that's a really good idea and very plausable.. how could you write a regex expression to search for that `s` character? – Gabriel Ortiz Apr 25 '19 at 22:46
  • Is your source transpiled/compiled to a built JavaScript file? Otherwise just check the raw source code and search with a regex for `>\s*[s]`. – ssc-hrep3 Apr 26 '19 at 07:37

2 Answers2

1

If the s is the the start of the string after the closing script tag and is the only text on that line, you could use a capturing group and use that group $1 in the replacement:

(<\/script>\s*\n)s$
  • ( Capturing group
    • <\/script>\s\n Match closing script tag followed by 0+ times a whitespace char and a newline
  • ) Close capturing group
  • s Match s
  • $ End of string

Regex demo

const s = `<script type="text/javascript"><\/script>
s`;

console.log(s.replace(/(<\/script>\s*\n)s$/, "$1"));
The fourth bird
  • 154,723
  • 16
  • 55
  • 70
0

If your app is php, try to search something like this in the beginning of the php file. This is a piece of code that will be just echoed, not executed.

s<?php
Anatoliy Gusarov
  • 797
  • 9
  • 22