regexp.js (2358B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 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 reExtnamePosix = require( './main.js' ); 24 25 26 // MAIN // 27 28 /** 29 * Captures a POSIX filename extension. Modified from Node.js [source][1]. 30 * 31 * Regular expression: `/^(?:\/?|)(?:[\s\S]*?)(?:(?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/` 32 * 33 * - `\^` 34 * - match any string which begins with 35 * 36 * - `(?:)` 37 * - capture but do not remember (root) 38 * 39 * - `\/?` 40 * - match a `/` literal zero or one time 41 * 42 * - `|)` 43 * - OR capture nothing 44 * 45 * - `(?:)` 46 * - capture but do not remember (directory) 47 * 48 * - `[\s\S]` 49 * - any space or non-space character 50 * 51 * - `*?` 52 * - zero or more times, but non-greedily (shortest possible match) 53 * 54 * - `(?:)` 55 * - capture but do not remember (basename) 56 * 57 * - `\.{1,2}` 58 * - match a `.` literal one or two times 59 * 60 * - `|` 61 * - OR 62 * 63 * - `[^\/]+?` 64 * - match anything which is not a `/` literal one or more times, but do so non-greedily 65 * 66 * - `|)` 67 * - OR capture nothing 68 * 69 * - `()` 70 * - capture 71 * 72 * - `\.` 73 * - match a `.` literal 74 * 75 * - `[^.\/]` 76 * - match anything which is not a `.` or `/` literal 77 * 78 * - `*` 79 * - zero or more times 80 * 81 * - `|)` 82 * - OR capture nothing 83 * 84 * - `(?:)` 85 * - capture but do not remember (trailing slash) 86 * 87 * - `[\/]` 88 * - match a `/` literal 89 * 90 * - `*` 91 * - zero or more times 92 * 93 * - `$` 94 * - end of string 95 * 96 * [1]: https://github.com/nodejs/node/blob/1a3b295d0f46b2189bd853800b1e63ab4d106b66/lib/path.js#L406 97 * 98 * @constant 99 * @type {RegExp} 100 * @default /^(?:\/?|)(?:[\s\S]*?)(?:(?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/ 101 */ 102 var RE_EXTNAME_POSIX = reExtnamePosix(); 103 104 105 // EXPORTS // 106 107 module.exports = RE_EXTNAME_POSIX;