Stop the regexp searching to first match
2 次查看(过去 30 天)
显示 更早的评论
I have a text a char array axs = 'ACCtl_nEpmNEng_AXIS "Group sampling point for curves (engine speed)" 0x806B139C Epm_nEng Axis_Xs16 32767.50 EngN 4 -16384.00 16383.50 FORMAT "%8.2" EXTENDED_LIMITS -16384.00 16383.50 DEPOSIT ABSOLUTE' and I'm tryng to exctract some information using the command regexp(axs,' +(?<name>\w+) +"(?<description>[^"]*)" +\d+x(?<address>\w+) +(?<input>\w+) +(?<formula>\w+) +\d+(\.\d+)* +\w+ +(?<dimension>\d+)',"names"). The problem is it's returning an empty structure but if the input changes removing 'FORMAT "%8.2"' it gives me what I want:
name 'ACCtl_nEpmNEng_AXIS'
description 'Group sampling point for curves (engine speed)'
address '806B139C'
input 'Epm_nEng'
formula 'Axis_Xs16'
dimension '4'
How can I get the same result also with the original text?
0 个评论
采纳的回答
Rik
2023-6-12
You're requiring 1 or more spaces at the start of your char array. Therefore, no match actually exists. Removing that requirement (or changing '+' to '*') solves the problem:
axs = 'ACCtl_nEpmNEng_AXIS "Group sampling point for curves (engine speed)" 0x806B139C Epm_nEng Axis_Xs16 32767.50 EngN 4 -16384.00 16383.50 FORMAT "%8.2" EXTENDED_LIMITS -16384.00 16383.50 DEPOSIT ABSOLUTE';
regexp(axs,'(?<name>\w+) +"(?<description>[^"]*)" +\d+x(?<address>\w+) +(?<input>\w+) +(?<formula>\w+) +\d+(\.\d+)* +\w+ +(?<dimension>\d+)',"names")
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!