Thread Subject: regexprep wildcard problem

Subject: regexprep wildcard problem

From: Christian Kuijlaars

Date: 23 Jan, 2008 08:46:01

Message: 1 of 7

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:35:02

Message: 2 of 7

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

don't repeat your post
us

Subject: regexprep wildcard problem

From: riccardo

Date: 23 Jan, 2008 13:40:19

Message: 3 of 7

"Christian Kuijlaars" <c.a.j.kuijlaars@student.tudelft.nl>
wrote in message <fn6us9$5fa$1@fred.mathworks.com>...
> 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
>

Christian,
it's not just wildcards.
You should familiarise yourself with the syntax of a
regular expression, because those 2 regexprep calls do not
make much sense, I'm afraid. (hint: ... square brackets
have a special meaning ...)
If Matlab's documentation is not clear, just search
for "regular expression" in google, you should find plenty
of stuff.
HTH
Riccardo

 

Subject: regexprep wildcard problem

From: Christian Kuijlaars

Date: 23 Jan, 2008 14:17:18

Message: 4 of 7

> Christian,
> it's not just wildcards.
> You should familiarise yourself with the syntax of a
> regular expression, because those 2 regexprep calls do
not
> make much sense, I'm afraid. (hint: ... square brackets
> have a special meaning ...)
> If Matlab's documentation is not clear, just search
> for "regular expression" in google, you should find
plenty
> of stuff.
> HTH
> Riccardo

I expected the brackets to have a special meaning...as i
kept trying and trying and the program just ignored the
brackets so to say. I know i should familiarise myself but
time is slowly diminishing for the project I'm working on.
Thanks anyway because I think I will need this after this
project probably again.

Subject: regexprep wildcard problem

From: per isakson

Date: 23 Jan, 2008 22:33:02

Message: 5 of 7

"Christian Kuijlaars" <c.a.j.kuijlaars@student.tudelft.nl>
wrote in message <fn6us9$5fa$1@fred.mathworks.com>...
> 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
>

>> regexprep({'atp[c]','atp[p]'}, '\[.\]', '')
ans =
    'atp' 'atp'
>>

This will work for any one character inbetween square
brackets. / per

Subject: regexprep wildcard problem

From: per isakson

Date: 23 Jan, 2008 22:37:01

Message: 6 of 7

"Christian Kuijlaars" <c.a.j.kuijlaars@student.tudelft.nl>
wrote in message <fn6us9$5fa$1@fred.mathworks.com>...
> 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
>

>> regexprep({'atp[c]','atp[p]'}, '\[[cp]\]', '')
ans =
    'atp' 'atp'

and to be a bit more specific /per

Subject: regexprep wildcard problem

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 23 Jan, 2008 22:55:25

Message: 7 of 7

In article <fn8fau$2u3$1@fred.mathworks.com>,
per isakson <poi.nospam@bimDOTkthDOT.se> wrote:
>"Christian Kuijlaars" <c.a.j.kuijlaars@student.tudelft.nl>
>wrote in message <fn6us9$5fa$1@fred.mathworks.com>...
>> I have the string 'atp[c]' which needs to be transformed
>> into 'atp', the same counts for 'atp[p]'.

>>> regexprep({'atp[c]','atp[p]'}, '\[.\]', '')
>ans =
> 'atp' 'atp'

>This will work for any one character inbetween square
>brackets. / per

Unfortunately it will also transform 'a[c]t[p]' to 'at' --
the pattern isn't anchored to only match terminal \[.\]
It will also do strange things to a[[]]tp

--
We regret to announce that sub-millibarn resolution bio-hyperdimensional
plasmatic space polyimaging has been delayed until the release
of Windows Vista SP2.

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 Riccardo 23 Jan, 2008 08:55:06
regular expression Riccardo 23 Jan, 2008 08:55:06
regexp Riccardo 23 Jan, 2008 08:55:06
code Christian Kuijlaars 23 Jan, 2008 03:49:55
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