Score:0

How to find an expression with an unknown number of letters in the bash?

ht flag

How do I match a phrase with an unknown number of letters in the bash

I have these lines.

This is a line **s838e**
This is a line **s9e**

I want grep to return any line that contains a statement with such a syntax، but the number of numbers in the middle of the expression is unknown. How do I do that?

this expression: SUnknown_number_of_numbersE

Should I use another tool?

If you don't understand my question، I'm sorry، my English is so bad.

Hannu avatar
ca flag
https://www.regular-expressions.info/
Score:0
my flag

If you have your code like this:

phrase='This is a line **s838e**'

You could make a test like this:

if [[ "$phrase" =~ ^This\ is\ a\ line\ \*\*s[0-9]+e\*\*$ ]]; then
    echo "match"
else
    echo "not match"
fi

If french is your mother tongue, you could read this page: https://fr.wikibooks.org/wiki/Programmation_Bash/Regex

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.