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
 
Ad

Advertisements


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

Top