Creating a regex to get multiple values and print

Joined
Feb 19, 2020
Messages
22
Reaction score
0
I'm looking for any help with the code below. Basically the ip-port string keeps changing and may contain more than one true value in str and i wonder if is possible to use a regex using the search function to get the all ip-port and print in demo.

Code:
<p id="demo"></p>

<script>
var str = "Please 127.0.0.1:80 locate where 127.0.0.2:80 occurs!";
var pos = str.search("\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):\d{1,5}\b");
document.getElementById("demo").innerHTML = pos;
</script>

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top