douxieshang5577 2017-01-04 16:39
浏览 892

Golang regExp用于将字符匹配到一个字符串(不包括子字符串)

I have a use case: Need to match the following . Input string: abpcdcccddd Matching criteria: match all characters starting with 'a' and ending with 'ccc' Example: abpcdccc ( single character 'c' in 4th Poistion got successfully ignored in matching)

Can you help me with the Golang regular expression for the same?

  • 写回答

2条回答 默认 最新

  • drd94483 2017-01-04 16:45
    关注

    I'm not sure that I understand exactly what it is you are wanting, but I can probably get you on the right track.

    If you want to match a string that has an a, followed by some word characters, followed by ccc, then you can simply use something like this:

    a\w+ccc
    

    If you want the string to start and end with a and ccc respectively, you can do something like this:

    ^a\w+ccc$
    

    If you want to only allow specific characters like lowercase letters, you can put them into a character class like this:

    a[a-z]+ccc
    

    Hopefully one of those answers your question.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!