Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

正则如何匹配测试#号注释?

我想计算出某行文本是不是注释

# 我是注释
a=我不是注释

  # 我是注释
a1=我不是注释

所以想要一个正则表达式 myregexp

myregexp.test('# 我是注释') // true
myregexp.test('   # 我是注释') // true
myregexp.test('a=我不是注释') // false

请问这个正则表达式怎么写呢?

为什么 /^?s#/.test('# 我是注释') 会报错呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

已解决 /^s*#/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...