dongquepao8653 2018-11-08 15:40
浏览 67
已采纳

编写高级正则表达式

Firstly sorry for my bad English. I'm newbie with regex. I'm trying to make auto translation. For example I have a text like:

/begin CHARACTERISTIC

    AccPed_trqEngLow_MAP
    "Kennfeld für AWD"
    MAP
    0x801B425C
    Map_Xs16Ys16Ws16
    1500.000
    Trq
    -500.0000
    1000.000

    FORMAT "%8.3"
    EXTENDED_LIMITS -3276.800 3276.700


    /begin AXIS_DESCR

        STD_AXIS
        Epm_nEng
        EngN
        16
        0.00
        10000.00

        FORMAT "%8.2"
        EXTENDED_LIMITS -16384.00 16383.50
        DEPOSIT ABSOLUTE

    /end AXIS_DESCR

    /begin AXIS_DESCR

        STD_AXIS
        AccPed_rAPP
        Prc
        8
        0.00
        100.0000

        FORMAT "%8.4"
        EXTENDED_LIMITS -400.0000 399.9878
        DEPOSIT ABSOLUTE

    /end AXIS_DESCR

/end CHARACTERISTIC

I need to select all strings in "" like "Kennfeld für AWD", but do not select where starts with % ("%8.3") Is it possible at least? Thanks in advance.. P.S string may contain quotation marks inside, like "Hello "world" !" It is very difficult for me.

  • 写回答

2条回答 默认 最新

  • dpict99695329 2018-11-08 16:15
    关注

    /\"([^%].*)\"/g matches all strings in quotes that don't start with a % symbol.

    In javascript (es6) it would be:

    const example = `
    /begin CHARACTERISTIC
    
        AccPed_trqEngLow_MAP
        "Kennfeld für AWD"
        MAP
        0x801B425C
        Map_Xs16Ys16Ws16
        1500.000
        Trq
        -500.0000
        1000.000
    
        FORMAT "%8.3"
        EXTENDED_LIMITS -3276.800 3276.700
    
    /end CHARACTERISTIC
    `
    
    let re =  /\"([^%].*)\"/g;
    let results = example.match(re);
    
    console.log(results)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog