![]() |
|
Perl-Sensitive Sunglasses | |
PerlMonks |
Basic Regex question with aby r.joseph (Hermit) |
on Dec 22, 2001 at 05:32 UTC ( #133926=perlquestion: print w/replies, xml ) | Need Help?? |
r.joseph has asked for the wisdom of the Perl Monks concerning the following question:
I didn't want to say it in the title, but this question has a little to do with Java. No, please don't leave! It's mainly a regex question, but I am using Java 1.4b3 instead of Perl because I have to, and I could think of no better source of regex-related knowledge than right here at the Monestary. Ok, now that I am done explaining myself, here is what I need. Say I have a string that looks like:
I would then like to do a search/replace to make the above string:
(Yes, you're are correct in thinking that I'm doing stuff with ANSI codes, and yes, ommitted the rest of the string because I don't want to type out all those codes). The problem is that Java has nothing like perl's wonderful s/// that does interpolation - there is a replace function, and you can do grouping with paren's in Java, but since all my color codes are static final String's in seperate inner classes, I can't easily interpolate what I need to replace the [something] tags with. Ok, so that might have been a little confusing, especially if you don't know Java. But like I said, you really don't need to, because my real question is about crafting a regular expression to do all the work for me, so I don't have to worry about Java. First of all, Java's regex engine, except for some advanced features, is almost exactly the same as Perl's, so just give me perl regex's. What I would like to do is create a regular expression that capture's (using paren's) all the text in the [...] tags in my string, so I can then look through just the text in those strings and decide what to do (most likely with a large switch statment). I tried: (Note: there is a miniumum of one, max of two characters in my [...] tags), but it only matched the FIRST tag, and that was it. So, is there a clever regex that I can use to do what I need to? Or is there more work that is going to need to be done, regardless of the language? Thanks a bunch for the help! r. j o s e p h "Violence is a last resort of the incompetent" - Salvor Hardin, Foundation by Issac Asimov
Back to
Seekers of Perl Wisdom
|
|