Extract words with RegEx

前端 未结 3 422
情深已故
情深已故 2020-12-12 06:33

I am new with RegEx, but it would be very useful to use it for my project. What I want to do in Javascript is this :

I have this kind of string \"/this/is/an/example

3条回答
  •  离开以前
    2020-12-12 06:55

    Use split()

    The split() method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.

    var str = "/this/is/a/test"; 
    var array = str.split('/');
    console.log(array);

    In case you want to do with regex.

    var str = "/this/is/a/test"; 
    var patt1 = /(\w+)/g;
    var result = str.match(patt1)
    console.log(result);

提交回复
热议问题