Why are the regular expressions the same, but the order is different, but the result of the check is different?

requirements are either positive integers or positive floating point numbers
xixi and are written in a different order

clipboard.png
haha xixi

clipboard.png

clipboard.png

here is the code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <title></title>
</head>
<body>
    <div class="container">
        <span>
            :
        </span>
        <div class="select_wrapper" style="display:inline-block;">
            <select name="reg" onchange="change()">
                <option value=""></option>
            </select>
        </div>
        <div>
            <span class="select_reg"></span>:
            <input type="text" class="tagret_str">
            <button class="btn" onclick="doReg()"></button>
            <p class="result">

</div> </div> <script> var RegExps = { xixi:/^([1-9]\d*\.\d+)|(0\.\d*[1-9]\d*)|([1-9]\d*)$/ , haha:/^([1-9]\d*)|([1-9]\d*\.\d+)|(0\.\d*[1-9]\d*)$/ }; var selectRegs = { xixi:"", haha:"haha" } function doReg(){ var tagret_str = $(".tagret_str").val(); var reg = RegExps[$("select").val()]; if(reg.test(tagret_str)){ $(".result").text("yes!").css("color","green"); }else{ $(".result").text("No!").css("color","red"); } } function change(){ var reg = RegExps[$("select").val()]; $(".select_reg").text(reg); } $(function(){ for(var key in selectRegs){ var optionHtml = `<option value="${key}">${selectRegs[key]}</option>`; $(".select_wrapper").find("select").append(optionHtml); } }) </script> </body> </html>
Oct.11,2021

^ and $can be removed. Does this cause the regularity to be different


regular writing is wrong and ugly: / ^\ d + (\.\ d +)? $/

here there must be a number around the decimal point, but the number is not required. Replace + with *

.
Menu