Regular Expression that checks the presence of a repeating Pattern

Asked

Viewed 246 times

2

How do I make a regular expression that this one has to repeat exactly one tot of times? For example, I would like to check if a line in a file contains this |1_CHAR exactly 8 times. By the way, it is possible for example to say that the character type has to be or espaço, or o, or *?

1 answer

1


You can use {n} for something that repeats a fixed number of times. For example, the regular expression a{8} recognizes a sequence of 8 characters a.

In addition, it also has {n,m} for "of n a m repetitions' and {,m} and {n,} for "up to m repeats and "at least n repeats", respectively.

  • \w recognizes an alphanumeric character - I think your regex is right if you take the \ws (and maybe add a \| at the end to recognize the 9th vertical bar)

  • 1

    That’s the way it is. If you don’t match the re.match returns None instead of a Match Object so just convert i to boolean or pass them on if

Browser other questions tagged

You are not signed in. Login or sign up in order to post.