2016-07-30 19:59
浏览 363


I am a noob about regular expressions (sorry). I was trying to make a very simple markup language that matches bold and italic and then converts them to HTML. Here is an example for bold that I'm using:

var bold = regexp.MustCompile("\\*([^\\*]+)\\*")

It matches everything between two asterisks. Now, I'd like it to match *test* but not \*test*. Since I don't know much about regular expressions but I'm trying to make this experiment, I'd like to know what's the way for that. I searched everywhere but couldn't find the way to make this work.

图片转代码服务由CSDN问答提供 功能建议

我是有关正则表达式的菜鸟(对不起)。 我正在尝试制作一种非常简单的匹配标记语言 粗体和斜体,然后将它们转换为HTML。 这是我正在使用的粗体示例:

  var粗体= regexp.MustCompile(“ \\ *([  ^ \\ *] +)\\ *“)

它匹配两个星号之间的所有内容。 现在,我希望它匹配 * test * ,但不匹配 \ * test * 。 由于我对正则表达式了解不多,但我正在尝试进行此实验,所以我想知道这样做的方式。 我到处搜索,但找不到使这项工作有效的方法。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douyu9012 2016-07-30 20:28


    Go does not support lookbehinds. So a workaround can be:

    打赏 评论

相关推荐 更多相似问题