Basic regular expression in JavaScript

后端 未结 6 2072
[愿得一人]
[愿得一人] 2021-01-23 04:55

For some time I\'ve been trying to understand regular expressions in JavaScript, but it is extremely complicated. You could tell me how do I redeem separately each of the values

6条回答
  •  被撕碎了的回忆
    2021-01-23 05:50

    I don't know if this answers your question, but what you're trying to achieve is best done with split:

    var parts = "/first/middle/last".split("/");
    
    var first = split[1];
    var middle = split[2];
    var last = split[3];
    

    Note that index would start at 0, but that will contain anything before the first occurrence of the split string. In your example, that would just be an empty string, since the string starts with a slash.

提交回复
热议问题