A regular expression that finds a group of one or more alphabets separated by a single space is
^([:alpha:]+?)+$
but I don't know why.
^
and $
are starting and ending.
[[:alpha:]+?] I don't know exactly what that means.
regex
[[:alpha:]] Means a set of alphabetic characters and matches any alphabetic character.
+ The number of appearances operator, 1..It means more than one or more.
? The number of appearances operator, which means 0..1 (0 or 1).
( ) Regular expression matching groups.
A. In order of interpret it in order.
[[:alpha:]]
B. Any alphabetic character.
[[:alpha:]]+
C. String consisting of one or more consecutive alphabets.
[[:alpha:]]+ ?
D. After a string of one or more consecutive alphabets appears, a space may appear or may not appear.
([[:alpha:]]+ ?)+
The preceding pattern D must be a string that repeats at least once.
Therefore, for convenience, the following string will be expressed as _(underbar).)
aa_bb_ccc
D appears 3 times to satisfy the regular expression.
aa_bb_ccc_
It is also acceptable if there are more blank characters as shown above.
© 2024 OneMinuteCode. All rights reserved.