Skip to content
Advertisement

Tag: regexp-replace

JavaScript: How to reduce IFs with REGEX

I’m working on the following function which I had to add a few IFs in case the string was shorter than the format the REGEX groups was expecting: Is there a way to remove the IFs and get the same output with just Regex? I’m looking for something like: complete: 999.999.999-99 partial: 999.999.9 Because the function will be called when

Remove dots and spaces from strings

I want to remove dots . and spaces with regex text.replace(/[ .]+/g, ”). This is an 8-string 12.34.5678; and this is another 13-string 1234 5678 9123 0 okay? But the main problem is that it removes all dots and spaces, from the sentence. Thisisan8-string12345678;andthisisanother13-string1234567891230okay? an 8-string 12.34.5678 another 13-string 1234 5678 9123 0 Needs to be converted to. an 8-string

regexp highlight search matching numbers

I’ve got a script from a friend, and tried to modified it. So that it highlights a string of numbers in a div. The problem is, that the output of the highlighted text becomes the regexp. Any solutions, what I’m doing wrong? https://jsfiddle.net/rrggrr/kgd4swha/6/ Answer Here’s a simple way of doing it: Use a string#replace using /(9756[0-9]{8})/g as the regex to

Advertisement