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: Help using textscan or sscanf
Replies: 21   Last Post: Jan 23, 2013 4:02 PM

Advanced Search

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

Posts: 1,376
Registered: 12/7/04
Re: Help using textscan or sscanf
Posted: Jan 23, 2013 12:19 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

In article <kdn7t6$ci1$1@newscl01ah.mathworks.com>,
"james bejon" <jamesbejon@yahoo.co.uk> wrote:

> % What's the rule for getting '09837381019' to '4412373810', e.g., "If there
> are 11 digits, hack off the first 3 and the last 2 and stick a 4412 on the
> front"?
>
> S = '09837381019';
> regexprep(S, '^[0-9]{3}([0-9]{6})[0-9]{2}$', '4412$1')
>
> % Seems like you have a lot of different cases and rules. If you list all of
> them, I'm sure we could come up with a regexp that will handle them all;
> otherwise, there's a risk that the regexps will mess each other up


Rather than '[0-9]', use '\d':

regexprep(S, '^\d{3}(\d{6})\d{2}$', '4412$1')

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.



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.