Je veux vérifier si ma variable a ce format --- foobar---> <some other stuff>
En d'autres termes, je veux savoir si le texte commence par --- foobar --->
comparer le texte (avec des tirets) en utilisant un script shell regex
J'utilisé grep -q
mais nous avons eu cette erreur:
$echo "--- foobar---> subtree " | grep -q "--- fooobar--->*"
grep: unrecognized option `--- fooobar--->*'
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
(Ceci est OSX
et grep's version is:
$ grep --v
grep (GNU grep) 2.5.1
Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
)
Comment réécrire ma regex pour correspondre à la chaîne attendue?
Merci.
pouvez-vous clarifier sur ce que vous attendez le * à agir? dès maintenant, comme il est écrit, vous lui dites de faire correspondre votre chaîne avec 0 ou plus ">" à la fin. Si vous voulez dire n'importe quel caractère après votre expression, il ressemblerait à ceci. "--- fooobar --->. *" – cepatt
Comme un commentaire secondaire, vous pouvez construire et tester des expressions régulières sur [www.regexlib.com] (www. regexlib.com) – cepatt
Juste ajouté la clarification. Je veux vérifier si le texte commence par '--- foobar --->' – user1508893