in reply to check for power of a number with regex
There is no "plain" regex that correctly determines whether a string's length is a square, or one that determines whether a string's length is a power of some other fixed number. The corresponding languages are not regular, and these two examples are typical examples of standard homework problems in a first theory of computation course.
Thus under your constraints, the key to such a regex must be in clever use of backreferences. But it's not clear how backrefs be useful. Backrefs can only really handle linear relations in the length of strings, while exponentiation is highly non-linear.
blokhead
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: check for power of a number with regex
by JavaFan (Canon) on Oct 26, 2009 at 08:29 UTC | |
by blokhead (Monsignor) on Oct 26, 2009 at 13:37 UTC |
In Section
Seekers of Perl Wisdom