Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

regex - Get filename from string path in javascript?

How to get the filename from string-path in javascript?

Here is my code

var nameString = "/app/base/controllers/filename.js"; //this is the input path string

do something here to get only the filename

var name = ???   //this value should equal to filename.js
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

   var nameString = "/app/base/controllers/filename.js";
   var filename = nameString.split("/").pop();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...