regexp.js (3047B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2021 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var reBasenameWindows = require( './main.js' ); 24 25 26 // MAIN // 27 28 /** 29 * Capture a Windows path basename. Modified from Node.js [source][1]. 30 * 31 * Regular expression: `/^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+|)(?:[\\\/]|)(?:[\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(?:\.[^.\/\\]*|))(?:[\\\/]*)$/` 32 * 33 * - `^` 34 * - match any string which begins with 35 * 36 * - `(?:)` 37 * - capture but do not remember (device) 38 * 39 * - `[a-zA-Z]:` 40 * - match any upper or lowercase letter and a `:` literal 41 * 42 * - `|` 43 * - OR 44 * 45 * - `[\\\/]` 46 * - match a `\` or `/` literal character 47 * 48 * - `{2}` 49 * - exactly `2` times 50 * 51 * - `[^\\\/]+` 52 * - match anything but a `\` or `/` literal one or more times 53 * 54 * - `[\\\/]+` 55 * - match a `\` or `/` literal one or more times 56 * 57 * - `[^\\\/]+` 58 * - match anything but a `\` or `/` literal one or more times 59 * 60 * - `|)` 61 * - OR capture nothing 62 * 63 * - `(?:)` 64 * - capture but do not remember (slash) 65 * 66 * - `[\\\/]` 67 * - match a `\` or `/` literal 68 * 69 * - `|)` 70 * - OR capture nothing 71 * 72 * - `(?:)` 73 * - capture but do not remember (dirname) 74 * 75 * - `[\s\S]` 76 * - match any space or non-space character 77 * 78 * - `*?` 79 * - zero or more times but do so non-greedily 80 * 81 * - `()` 82 * - capture (basename) 83 * 84 * - `(?:)` 85 * - capture but do not remember 86 * 87 * - `\.{1,2}` 88 * - match a `.` literal one or two times 89 * 90 * - `|` 91 * - OR 92 * 93 * - `[^\\\/]+?` 94 * - match anything but a `\` or `/` literal one or more times, but do so non-greedily 95 * 96 * - `|)` 97 * - OR capture nothing 98 * 99 * - `(?:)` 100 * - capture but do not remember (extname) 101 * 102 * - `\.` 103 * - match a `.` literal 104 * 105 * - `[^.\/\\]*` 106 * - match anything but a `.`, `/`, or `\` literal zero or more times 107 * 108 * - `|)` 109 * - OR capture nothing 110 * 111 * - `(?:)` 112 * - capture but do not remember (trailing slash) 113 * 114 * - `[\\\/]*` 115 * - match a `\` or `/` literal zero or more times 116 * 117 * - `$` 118 * - end of string 119 * 120 * [1]: https://github.com/nodejs/node/blob/1a3b295d0f46b2189bd853800b1e63ab4d106b66/lib/path.js#L65 121 * 122 * @constant 123 * @type {RegExp} 124 * @default /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+|)(?:[\\\/]|)(?:[\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(?:\.[^.\/\\]*|))(?:[\\\/]*)$/ 125 */ 126 var RE_BASENAME_WINDOWS = reBasenameWindows(); 127 128 129 // EXPORTS // 130 131 module.exports = RE_BASENAME_WINDOWS;