I have this template for my command line: based on for C ++.
^s?([/|@#])(?:(?!\1).)+\1(?:(?!\1).)*\1(?:(?:gi?|ig)?(?:\1\d\d?)?|i)?$
ECMAScript 262
This is a special template to check if the user is entered into the correct command or not. This is a test against this line:
optional-s/one-or-more/anything/optional-g-or-i/optional-2-digits
Here is my previous question why I need this template .
Although it works fine on Linux, it does not work on Windows. I also know about line breaks on two machines, and I have read this: How are \ n and \ r handled differently on Linux and Windows?
My program works with any files, it receives only the first argument of the command line argv[ 1 ]and std::regex_match, if the correct input-user synopsis is correct or not.
For example: ./program 's/one/two/' *.txtwhich simply renames one to two for all txt files
C ++ code:
std::string argv_1 = argv[ 1 ]; // => s/one/two/
bool rename_is_correct =
std::regex_match( argv_1, std::basic_regex< char >
( "s?([/|@#])(?:(?!\\1).)+\\1(?:(?!\\1).)*\\1(?:(?:gi?|ig)?(?:\\1-?[1-9]\\d?)?|i)?" ) );
Problem:
Although the pattern is not greedy ; on Windows, it becomes greedy and matches more than 4 delimiters. Therefore, it does not have to match /one/two/three/four/five/, but this line matches!
NOTE:
- I deliberately rejected the statements
^and $, since there are defaults in C ++ relays std::regex_match, there is no need to use them \\; - escape-- javescript code
no
const regex = /^s?([/|@#])(?:(?!\1).)+\1(?:(?!\1).)*\1((?:gi?|gi)\1-?[1-9]\d|i)?$/gm;
var str = 's/one/two/gi/-33/';
if( str.match( regex ) ){
console.log( "okay" );
} else {
console.log( "no" );
}
Hide result
- , ?
.