Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


fd
Posts:
43
Registered:
7/24/09


A question about string patterns
Posted:
Aug 1, 2010 4:57 AM


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 lookbehind seems to be essential.
The tutorial in advanced string patterns from WR says Mathematica pattern lacks lookahea/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/lookbehind, 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



