440,034 Members | 2,000 Online
Need help? Post your question and get tips & solutions from a community of 440,034 IT Pros & Developers. It's quick & easy.

# string parsing / regexp question

 P: n/a I need to parse the following string: $$\pmatrix{{\it x_2}\cr 0\cr 1\cr }=\pmatrix{\left({{{\it m_2}\,s^2 }\over{k}}+1\right)\,{\it x_1}-{{F}\over{k}}\cr -{{{\it m_2}\,s^2\,F }\over{k}}-F+\left({\it m_2}\,s^2\,\left({{{\it m_2}\,s^2}\over{k}}+1 \right)+{\it m_2}\,s^2\right)\,{\it x_1}\cr 1\cr }$$ The first thing I need to do is extract the arguments to \pmatrix{ } on both the left and right hand sides of the equal sign, so that the first argument is extracted as {\it x_2}\cr 0\cr 1\cr and the second is \left({{{\it m_2}\,s^2 }\over{k}}+1\right)\,{\it x_1}-{{F}\over{k}}\cr -{{{\it m_2}\,s^2\,F }\over{k}}-F+\left({\it m_2}\,s^2\,\left({{{\it m_2}\,s^2}\over{k}}+1 \right)+{\it m_2}\,s^2\right)\,{\it x_1}\cr 1\cr The trick is that there are extra curly braces inside the \pmatrix{ } strings and I don't know how to write a regexp that would count the number of open and close curly braces and make sure they match, so that it can find the correct ending curly brace. Any suggestions? I would prefer a regexp solution, but am open to other approaches. Thanks, Ryan Nov 28 '07 #1
5 Replies

 P: n/a On Nov 28, 11:32 am, "Ryan Krauss"

 P: n/a On Nov 28, 1:23 pm, Paul McGuire

 P: n/a Paul McGuire wrote: On Nov 28, 1:23 pm, Paul McGuire As Tim Grove points out, ... s/Grove/Chase/ Sorry, Tim! No problem...it's not like there aren't enough Tim's on the list as it is. :) -tkc Nov 28 '07 #4

 P: n/a Interesting. Thanks Paul and Tim. This looks very promising. Ryan On Nov 28, 2007 1:23 PM, Paul McGuire

 P: n/a On Nov 28, 2007 1:23 PM, Paul McGuire

### This discussion thread is closed

Replies have been disabled for this discussion.