Meaning of javascript text between two slashes

前端 未结 3 1399
无人及你
无人及你 2020-12-11 22:40

On Dreamweaver if I write on a Javascript document some text between two slashes like




        
相关标签:
3条回答
  • 2020-12-11 23:27

    You can use regular expression literals like this:

    var pattern = /([0-9]+)/;
    if(pattern.test(someString)) {
        // ...
    } else {
        // ...
    }
    

    See also: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions

    0 讨论(0)
  • 2020-12-11 23:29

    It's a RegExp literal. I recommend doing your own research on the topic. I could write an introduction to finite automata and regular languages, but you'd always be able to find a better introduction with a little searching.

    0 讨论(0)
  • 2020-12-11 23:32

    It is the regular expression literal.

    From w3schools:

    var patt=new RegExp(pattern,modifiers);
    
    or more simply:
    
    var patt=/pattern/modifiers; 
    

    And from MDN:

    RegExp(pattern [, flags])
    
    /pattern/flags
    
    0 讨论(0)
提交回复
热议问题