题解 | #合法IP#
合法IP
https://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9
正则表达式的运用 完整代码如下:
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { // Write your code here while(line = await readline()){ let output = 'YES'; let arr = line.split('.').filter(Boolean); if (line.match(/\s/g)) { output = "NO"; } if (Math.min(...arr) < 0 || Math.max(...arr) > 255) { output = 'NO' } if (arr.length != 4) { output = 'NO' } for (let i = 0; i < arr.length; i++) { if (arr[i].toString().match(/^[0\+\-]\d+$/)) { output = 'NO' } } console.log(output); } }()