pasu857 Posted September 20, 2003 Posted September 20, 2003 I am trying to get Regex to match something like this: __X__Y__ __X_x__Y__ etc in particular, I want the content between those "__", so in the first example I will get X and Y, while in the second example I should get "X_x" and Y. So far I have got to the following Regex: Regex X = new Regex(@"__(?<object>[\w]+?)__"); This match __X__ and __X_x__, etc, and I can refer the content through the group name "object". But I don't know how to go on from there. Is there someone out there that can point me in the right direction? Many Thanks. Quote
Gladimir Posted September 20, 2003 Posted September 20, 2003 Not understanding the question... I'm not quite catching the question. Are you capturing the 'Y' as well as the 'X' and 'X_x' matches with that expression? Or perhaps you are purposefully omitting the 'Y'? Quote Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
pasu857 Posted September 20, 2003 Author Posted September 20, 2003 I am trying to capture all the X, Y and X_x (those are just examples). I want to capture all the content in between those "__". Sorry for the confusion. Quote
wyrd Posted September 20, 2003 Posted September 20, 2003 Edit: Made a few alterations to the regular expression Maybe something like this; "^(?<=_{2})(?<name>(\w+|\w+_{1}\w+))(?=_{2})$" Basically it's saying, get a match for any word or word_word between __ and __ starting at the beginning of the string and going until the end. It may not work exactly (regular expressions hardly do on the first try), but the key thing to note here is the either/or symbol | which returns a match of either expression. Hope this helps. Quote Gamer extraordinaire. Programmer wannabe.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.