RegExp Match only with paths contains filename

regex get filename from path without extension
regex get filename from path javascript
regular expression for file path checking
regex match exact file path
regex match file path
regex get filename from url
regex filename
regex match directory name

I am trying to create a Regexp in JS that only look into string having files and ignore the paths which don't have a filename.

input

tanxe\src\lib\hello
tanxe\lib\hello\world\verboseBackup.js
tanxe\src\hello\verboseBackup.js
tanxe\lib\verboseBackup.js

Trying

input.match(/^tanxe.*?lib.*?\\..*/i)

Expected Output:

tanxe\lib\hello\world\verboseBackup.js
tanxe\lib\verboseBackup.js

8.23. Extract the Filename from a Windows Path, Selection from Regular Expressions Cookbook, 2nd Edition [Book] You have a string that holds a (syntactically) valid path to a file or folder on a Windows It can't contain any colons or backslashes, so it cannot be confused with When it does match, it will match only the filename, so we don't need to use any capturing . I'm skeptical a regex would be faster than getting the index of the last path separator, but I could be wrong. – Dave Newton Jul 15 '14 at 23:18 This question is vague as it only contains one example of path and filename structure. Regex is used to match and/or capture different structures which have some similarity.

You might try this: tanxe\\lib.*?\.\w+ It matches paths starting with tanxe\lib and ending with a file extension.

RegExp Match only with paths contains filename, regex get filename from path without extension regex get filename from path javascript regular expression for file path checking regex match exact file path When matching buffer lines, e.g. using re-search-forward, you should anchor your regexp with ^ and $ to denote the beginning and end of each line, respectively. When matching filename strings as per my examples, however, it is instead better to use \\` and \\' to denote the beginning and end of the string, respectively.

input.match(/^tanxe\\lib\\(\w+\\)*\w+\.\w+/gi);

See the regExr fiddle I created.

Regex that matches path, filename and extension, to match a string containing a valid path, file name and extension. Finally The grouping parentheses is used only to delimit the pattern that  I added {0,1} to replace the + in the expression. Now the regex will return true in your scenario. You need to test it out to make sure it work correctly because the original intent of this regular expression is to validate file path and extension.

Your regex is work, I think you need is additional flags: g global, m multiline

var input = `tanxe\\src\\lib\\hello
tanxe\\lib\\hello\\world\\verboseBackup.js
tanxe\\src\\hello\\verboseBackup.js
tanxe\\lib\\verboseBackup.js
D:\\Program Files\\atom\\.atom\\packages\\utilities-tanxe\\lib\\abc\\verboseBackup.js`

input.match(/^.*tanxe.*?lib.*?\..*/gmi).forEach(r => console.log(r))
// start with "tanxe"
//input.match(/^tanxe.*?lib.*?\..*/gmi).forEach(r => console.log(r))

Finding Files - Finding Files, Test: -iregex expr. True if the entire file name matches regular expression expr . This is a match on the whole path, not a search. If a pattern contains metacharacters, locate only displays file names that match the pattern exactly. As a result  Regular Expression to Validate file name & Extesions. Character classes. any character except newline \w \d \s: word, digit, whitespace

Try this one too.

 tanxe\\[a-zA-Z\\]+[.]{1}[a-zA-z]{2,3}

6.5. Find a file by using the PathMatcher class, public interface PathMatcher { /** * Tells if given path matches this matcher's pattern. is matched using a limited pattern language that resembles regular expressions but with a simpler syntax. *[0-9]* - Matches file names containing a numeric value. The ? character matches exactly one character of a name component. Problem 5: Matching specific filenames If you use Linux or the command line frequently, are often dealing with lists of files. Most files have a filename component as well as an extension, but in Linux, it is also common to have hidden files that have no filename.

glob – Filename pattern matching, The pattern rules for glob are not regular expressions. Instead, they follow standard Unix path expansion rules. There are only a few special characters: two​  Though the regex engine scans the string from left to right, the anchor at the end of the regex makes sure that only the last run of filename characters in the string will be matched, giving us our filename. If the string ends with a backslash, as it will for paths that don’t specify a filename, the regex won’t match at all.

Finding Directories With Regular Expressions, This method locates files that match the regular expression defined. Eliminate the directory path, so the program can test only the file name Specialized") contains a collection of key-value pairs of strings, and provides the  - How to validate image file extension with regular expression It doesn’t work if the filename contains spaces. Bits And Pix » RegEx: Match filename with

glob – Filename pattern matching, The pattern rules for glob are not regular expressions. Instead, they follow standard Unix path expansion rules. There are only a few special characters: two​  Regular expressions (regex) match and parse text. The regex language is a powerful shorthand for describing patterns. Powershell makes use of regular expressions in several ways. Sometimes it is easy to forget that these commands are using regex becuase it is so tightly integrated.

Comments
  • Try /^tanxe\\lib.*?\\.[^\\]*$/i
  • @Wasim remove ^ to match line contains