regex - Python Regular expression: is there a symbol to search for more than one occurence of a pattern? -
i know *
0 or more, , +
1 or more, if wanted indicate 2 or more (more 1)?
for example, have
>>> y = 'u0_0, p33, avg' >>> re.findall(r'[a-za-z]+', y) ['u', 'p', 'avg']
but want obtain ones have 2 or more letters. in example, avg
.
how do this?
y = 'u0_0, p33, avg' print re.findall(r'[a-za-z]{2,}', y) ^^^
{m,n} causes resulting re match m n repetitions of preceding re, attempting match many repetitions possible. example, a{3,5} match 3 5 'a' characters. omitting m specifies lower bound of zero, , omitting n specifies infinite upper bound. example, a{4,}b match aaaab or thousand 'a' characters followed b, not aaab. comma may not omitted or modifier confused described form.
Comments
Post a Comment