我正在寻找常规表达式,我可以输入特殊字符出现次数的限制。
示例:我必须在整个文本中将*
限制为5
的最大数量,因此它应为stack***over*f**low
。
我在我的指令中尝试过这样:
var transformedInput = text.replace(/[^0-9][*]{6}/g, '');
但它没有用。有人可以帮帮我吗?
答案 0 :(得分:0)
不确定为什么需要更换,也许您正试图阻止输入星号?无论如何,我建议你稍微扩大你的范围,并允许更多的JS来做一些繁重的工作。如果要阻止输入字符,可以在每次按键事件中检查星号的长度。
# python code to run the hilbert curve pattern
# from http://www.fundza.com/algorithmic/space_filling/hilbert/basics/index.html
import sys, math
def hilbert(x0, y0, xi, xj, yi, yj, n):
if n <= 0:
X = x0 + (xi + yi)/2
Y = y0 + (xj + yj)/2
# Output the coordinates of the cv
print '%s %s 0' % (X, Y)
else:
hilbert(x0, y0, yi/2, yj/2, xi/2, xj/2, n - 1)
hilbert(x0 + xi/2, y0 + xj/2, xi/2, xj/2, yi/2, yj/2, n - 1)
hilbert(x0 + xi/2 + yi/2, y0 + xj/2 + yj/2, xi/2, xj/2, yi/2, yj/2, n - 1)
hilbert(x0 + xi/2 + yi, y0 + xj/2 + yj, -yi/2,-yj/2,-xi/2,-xj/2, n - 1)
def main():
args = sys.stdin.readline()
# Remain the loop until the renderer releases the helper...
while args:
arg = args.split()
# Get the inputs
pixels = float(arg[0])
ctype = arg[1]
reps = int(arg[2])
width = float(arg[3])
# Calculate the number of curve cv's
cvs = int(math.pow(4, reps))
# Begin the RenderMan curve statement
print 'Basis \"b-spline\" 1 \"b-spline\" 1'
print 'Curves \"%s\" [%s] \"nonperiodic\" \"P\" [' % (ctype, cvs)
# Create the curve
hilbert(0.0, 0.0, 1.0, 0.0, 0.0, 1.0, reps)
# End the curve statement
print '] \"constantwidth\" [%s]' % width
# Tell the renderer we have finished
sys.stdout.write('\377')
sys.stdout.flush()
# read the next set of inputs
args = sys.stdin.readline()
if __name__ == "__main__":
main()