Thread Subject: regexprep wildcard problem

Subject: regexprep wildcard problem

From: Christian Kuijlaars

Date: 23 Jan, 2008 08:49:01

Message: 1 of 6

Hello,

Regexp and regexprep are great functions but for someone
who has not a very large history in programming the way
wildcards are dealt with in the code is a bit hard to
understand and the help file is not as complete as I had
hoped. However I need something replaced in my code and
maybe someone could help me.

I have the string 'atp[c]' which needs to be transformed
into 'atp', the same counts for 'atp[p]'.

I tried
regexprep({'atp[c]','atp[p]'}, '[]', '')
and
regexprep({'atp[c]','atp[p]'}, '[(\w+).*?]', '')
and many more but mostly the results are '[]' or atp[ or
atp[] but never 'atp'. I am at a loss, and I know it is
possible.

thanks

Subject: regexprep wildcard problem

From: us

Date: 23 Jan, 2008 09:20:18

Message: 2 of 6

"Christian Kuijlaars":
<SNIP rex-headache...

one of the many solutions

     s={'abc[c]','defg[C]hi','j[dDd]'};
     m=regexp(s,'\w*(?=(\[))','match');
     r=[m{:}];
     disp(r)
% ans = 'abc' 'defg' 'j'

us

Subject: regexprep wildcard problem

From: us

Date: 23 Jan, 2008 09:25:03

Message: 3 of 6

"Christian Kuijlaars":
<SNIP getting impatient...

don't repeat your post
us

Subject: regexprep wildcard problem

From: Christian Kuijlaars

Date: 23 Jan, 2008 09:39:02

Message: 4 of 6

"us " <us@neurol.unizh.ch> wrote in message
<fn715f$6at$1@fred.mathworks.com>...
> "Christian Kuijlaars":
> <SNIP getting impatient...

What are those SNIP comments?

About the extra post, was an accident, I tried to remove
it but that does not seem possible.

I tried your piece of code with regexprep but I got for
example from {'atp[c]', 'atp[p]'}
[c]
[p]

and i needed:
atp
atp

i tried to move the /w* because i think that was the
problem but it wasn't ofcourse.

thanks again

Subject: regexprep wildcard problem

From: us

Date: 23 Jan, 2008 09:45:03

Message: 5 of 6

"Christian Kuijlaars":
<SNIP did not follow the snippet...

> I tried your piece of code with regexprep but I got for
> example from {'atp[c]', 'atp[p]'}
> [c]
> [p]
> and i needed:
> atp
> atp

that's exactly what you get with the solution i've shown

     s={'atp[c]','atp[p]'};
     m=regexp(s,'\w*(?=(\[))','match');
     r=[m{:}]
% ans = 'atp' 'atp'

us

Subject: regexprep wildcard problem

From: Christian Kuijlaars

Date: 23 Jan, 2008 10:19:03

Message: 6 of 6

> that's exactly what you get with the solution i've shown
>
> s={'atp[c]','atp[p]'};
> m=regexp(s,'\w*(?=(\[))','match');
> r=[m{:}]
> % ans = 'atp' 'atp'
>
> us

That is exactly right. Probably was a bit too focussed on
the regexprep. Anyway got it working now with the code
above. Many thanks.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
regexprep Christian Kuijlaars 23 Jan, 2008 04:34:48
regular expression us 23 Jan, 2008 04:25:06
regexp us 23 Jan, 2008 04:25:06
code Christian Kuijlaars 23 Jan, 2008 03:50:05
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com