I have a program command-linethat its first argument ( = argv[ 1 ] )is a regular expression pattern.
./program 's/one-or-more/anything/gi/digit-digit'
So I need a regular expression to check if the input I entered is correct from the user or not . This regular expression can be easily solved, but since I'm using C ++ library, std::regex_matchand this feature by default puts begin and end the assert ( ^and $) in the row, so quantifier nan-greedy ignored.
Let me clarify this question. If I want to compare /anything/, I can use /.*?/, but std::regex_matchconsider this as a template ^/.*?/$, and therefore, if the user enters: /anything/anything/anyhting/, std::regex_matchstill returns true when the input pattern is incorrect . std::regex_matchreturns only true or false , and the expected form of the template can only be text in accordance with the template. Since the picture is different, here I cannot provide you with all the possibilities, but I give you an example.
Should match
/.//
s/.//
/.//g
/.//i
/././gi
/one-or-more/anything/
/one-or-more/anything/g/3
/one-or-more/anything/i
/one-or-more/anything/gi/99
s/one-or-more/anything/g/4
s/one-or-more/anything/i
s/one-or-more/anything/gi/54
and anything look like this pattern
Rules:
- delimiters
/|@# sthe letter at the beginning and g, iand 2 digits at the end are optionalstd::regex_match true, - , false+*- g i
- 3
/.// /./ - ECMAScript 262
, , .
.