I'm trying to generate a regular expression to detect any string that :
- Starts with the [
- Ends with ]
- Contains any word or number or space
Example : [Maxsens8 Innovations]
This regular expression does not match to expressions that i'm looking for and i thing the problem
is about the last character .
I will be gratefull if someone explain to me how to generate the right regular expression that
detect strings like : [Maxsens Innovations] [Verifik8] [Divoluci] ...
CodePudding user response:
Try:
^\[[a-zA-Z0-9 ]*\]$
or
^\[[a-zA-Z0-9\s]*\]$
\]$
Match]
followed by end of line ($
)[
and]
are meta-characters hence should be escaped.- Use
\s
to match any white-space char (includingnewline
) or singlespace
.
Note: This shall match against single input line. If you have multiple fragments per line then skip the line start and end markers viz., ^
and $
.