dsaff82024 2013-02-12 18:14
浏览 260
已采纳

我如何编写正则表达式来检查由等号分隔的文本字符串?

How would i use regular expressions to check for characters within the following string of text:

=== logo ===

I tried to use a regex tester but could come up with the correct expression for i've tried this:

 /^[=]{3}$/
  1. I want search within a string find where the text starts with 3 equal signs.
  2. Find a string or any other characters within the equal signs.
  3. Find 3 more equal signs.. ending the expression.

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • douyinliu8813 2013-02-12 18:16
    关注

    Try using this regex:

    /===[^=]+===/
    

    If you want to capture the text, surround it in parentheses:

    /===([^=]+)===/
    

    Here's the fiddle: http://jsfiddle.net/jufXA/


    If you might have equal signs in your text (but less than 3, obviously) you should instead match everything lazily (which is a tad slower):

    /===(.+?)===/
    

    Here's the fiddle: http://jsfiddle.net/jufXA/1/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)