필터 지우기
필터 지우기

Proper lookaround assertion within regexp?

조회 수: 1 (최근 30일)
Nicholas Kavouris
Nicholas Kavouris 2022년 3월 12일
댓글: Walter Roberson 2022년 3월 14일
Below sample of text generated from component readings and have to extract the Auger RPM and Fan RPM Sperately, what is the proper exrpression within the regexp function. I am currently using lookaroun assertions to do my selections.
Auger PWM: 135/255 RPM: 158 CCW: 1
AugerMaxReady 1
AugerReversed 0
Fan PWM: 192 RPM: 3750
Current Code as follows grabs all RPM values, instead of only fan or only auger. How do i give proper expression to select the RPM Value in the Correct column?
Auger_RPM=regexp(A,'(?<=RPM:).\d*(?!CCW:)','match')

답변 (1개)

Walter Roberson
Walter Roberson 2022년 3월 12일
A = "Auger PWM: 135/255 RPM: 158 CCW: 1" + newline + "Fan PWM: 192 RPM: 3750"
A =
"Auger PWM: 135/255 RPM: 158 CCW: 1 Fan PWM: 192 RPM: 3750"
Auger_RPM = regexp(A, '(?<=^Auger.*RPM:\s+)\d+', 'dotexceptnewline', 'match', 'once', 'lineanchors')
Auger_RPM = "158"
Fan_RPM = regexp(A, '(?<=^Fan.*RPM:\s+)\d+', 'dotexceptnewline', 'match', 'once', 'lineanchors')
Fan_RPM = "3750"
  댓글 수: 2
Nicholas Kavouris
Nicholas Kavouris 2022년 3월 14일
unfortunately neither of these lines work to find the proper data from the text file
Walter Roberson
Walter Roberson 2022년 3월 14일
Is 158 and 3750 not the proper data? Were you trying to extract the 135/255 and 192 instead of the RPM field?
Or is your file different than what you outlined?
Perhaps you could attach an example file for testing.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by