[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: Advance Regex help

Chris Velevitch wrote:
How do I search for a pattern only if the pattern is before a specific character eg '%'. For example:-

     1. pattern % something
     2. something % pattern

I want to be able to match line 1 but not line 2.

Any ideas?

For a reference, you can have a look at http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html

In your case, I suppose that this should suffice:
pattern.*[%]
which matches the pattern followed by any number of chars terminated by '%' (you need brackets only if the terminator is a metacharacter).
This is not exactly what you where looking for (match the pattern ONLY IF...), but I think that shouldn't be a problem.


In particular, if you are using the regex for a replacement, you can simply define a capturing group by adding parentheses around the string you don't need and re-write it with $1:
FIND
pattern(.*[%])
REPLACE WITH
anotherpattern$1


HTH,
dyd