简体   繁体   中英

Remove blankspace from postalcodes on webpage with greasemonkey

I got a webpage with alot of random postalcodes that look like this on a webpage that are spread out: 423 43
324 42
123 45
342 39
etc
What code can I use to remove only the blankspace from all of them between the first three digits and the last two.
Ex 123 45 -> 12345

You can try to use a string replace regex.

Fiddle - http://jsfiddle.net/E8gHR/

For example:

$('span').each(function(){
    var number = $(this).text().replace(/(\d\d\d)(\s)(\d\d)/g, '$1'+'$3'); 
    $(this).text(number);
});

Here is an example of a code to remove spaces from ONE string.

var str = '123 45'; 
str = str.replace(/\s+/g, ''); // removing all White-spaces from the string

If you want to remove all white-spaces/spaces from all the strings at the same time, than I have to see the HTML to work something out

Good luck

:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM