Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Question Using Regexpi
Replies: 11   Last Post: Jul 8, 2013 10:35 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,187
Registered: 6/7/07
Re: Question Using Regexpi
Posted: Jul 3, 2013 1:00 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 7/3/2013 10:32 AM, dpb wrote:
...

> I'm no regexp user but '$' doesn't return the last occurrence of a match
> in a strung but the match _followed_immediately_ by the \n sequence.
>
> You need a search from the end to then find the first full word that is
> numeric it would appear. I don't know enough regexp otomh to do it on
> the fly, sorry...but as you've discovered '$' isn't that.


One would think that

regexp(String,'<\\d\>','match')

would find a word containing only digits but it doesn't succeed,
either... :(

>> regexp(String,'<\\d\>','match')
ans =
{}
>>

OK, is it something about using '\d' inside the <\ ????

>> regexp(String,'<\[0-9]\>','match')
ans =
{}
>>

No, no joy...

OK, are there some other non-printing characters masquerading as
whitespace or somesuch????

>> findstr(String,' ')
ans =
4 8 9 11 12 13 14 17

Nope, blanks on either side so _should_ be a word...

>> regexp(String,'\d','match')
ans =
'1' '6' '1'
>> regexp(String,'[ \d ]','match')
ans =
Columns 1 through 7
'1' ' ' ' ' ' ' ' ' ' ' ' '
Columns 8 through 11
' ' '6' '1' ' '

And, finds the individual digits surrounded by blanks just to prove it...

OK, let's just parse the form...

>> String
String =
NR1 MGT - 61 HOURS
>> v=sscanf(String(findstr(String,'-')+1:end),'%d')
v =
61
>>

Such is why I've always become so frustrated w/ regexp before ever
actually got anything to work pretty much gave up trying for lack of
interest in figuring it out enough to understand why what seems that
should doesn't. More interesting things to do than pore over regexp
documentation that seems nearly impenetrable at first blush... :(

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.