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.math.mathematica

Topic: A question about string patterns
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
fd

Posts: 43
Registered: 7/24/09
A question about string patterns
Posted: Aug 1, 2010 4:57 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Dear Group

I'm kind of starting with string patterns with Mathematica and would
like to make sense of some questions.

I was sorting out a string matching problem in Vim where I needed to
find all strings not enclosed by double quotes (\"). To do this a
regular expression with look-behind seems to be essential.

The tutorial in advanced string patterns from WR says Mathematica
pattern lacks look-ahea/look behind type of functions, anyway, I tried
with Mathematica and found that it was really easy, the solution (I
suppose) I found in mathematica is

text = "this is a text with \"quotes\" we wish to select and there \
are more than \"one\" whole \"set \" of them \"the end\""

StringReplace[text, (x :
Except["\""] ...) ~~ (y : ("\"" ~~ Except["\""] ... ~~
"\"") ...) :> ToUpperCase[x] ~~ y]

So my questions are:

1) is there some type of problem that can only be solved with look-
ahead/look-behind, so that RegularExpression[] or some piece of
Mathematica code had to be used?

2) It seems to me that look behind/ahead constructs can be somehow
emulated with named patterns in Mathematica, is this always the case?

Finally, I'd be really glad to know of anyone else's solution to this
problem (either mathematica or regexp). Any other comment/thoughts on
this problem would be greatly appreciated.

Best
Felipe





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.