【问题标题】:simple regexp in MatlabMatlab中的简单正则表达式
【发布时间】:2014-03-26 23:04:59
【问题描述】:

假设我有以下字符串

begin: - number 1: word_12

begin: - number 3: word_31

begin: - number 3: word_11

begin: - number 9: word_43

基本上我只想选择number \d: 之后的文本(即word_12word_31 等)在Matlab 中使用正则表达式沿着regexp((?<=[number ]\d: .*),'match') 这些行,但我不知道如何构造正则表达式...

【问题讨论】:

    标签: regex string matlab


    【解决方案1】:
    s = {'begin: - number 1: word_12';
         'begin: - number 3: word_31';
         'begin: - number 3: word_11';
         'begin: - number 9: word_43'};%a cell array of strings
    
    re = '.*number \d: (.*)';
    
    A = regexp(s,re,'tokens'); %a cell array of cells containing strings
    

    使用正则表达式的输出有点有趣,因为您必须“取消引用”单元格两次才能得到一个字符串——例如。

    A{1}{1}
    
    ans = 
    
        'word_12'
    

    有关更多信息,我发现 Matlab 的 regexp 帮助页面非常有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-17
      • 2013-06-09
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多