Solved

regex exclusion

Posted on 2008-10-22
4
566 Views
Last Modified: 2008-10-22
Hi,

I using RegexBuddy to test a java regex expression that will match any string except one with "abc" anywhere in the string.

I.e. Match any strings except the ones with "abc"

1) www.test.com/ad/click-imp/ref?=center=701&pf_rd_i=2&p
2) www.test.com/abc/click-imp/ref=center=701&pf_rd_i=2&p
3) www.test.com/inventory_rep2_mn=70/abc/ws_gh790?%5Fencoding=UTF8
4) www.test.com/promotion/h/ref=xg_2_center/gh_321?%5Fencoding=UTF8

So I want to match string 1 and 4 but not 2 and 3. I tried a bunch of expression but so far the closest I've come is www.test.com/([^abc]++).*

Can an expert help me out?

0
Comment
Question by:acclimate
  • 3
4 Comments
 
LVL 27

Expert Comment

by:ddrudik
ID: 22781760
 Pattern re = Pattern.compile("^(?:(?!abc).)*$",Pattern.DOTALL);
0
 

Author Comment

by:acclimate
ID: 22781833
Hi ddrudik,

I read a bunch of your other posts yesterday :)

I can't do the java commands because the application I'm using will only input regex. DOTALL and Pattern are taken literally.


0
 
LVL 27

Accepted Solution

by:
ddrudik earned 500 total points
ID: 22782239
(?s)^(?:(?!abc).)*$

or:

^(?:(?!abc)(?:.|\n))*$

or:

^((?!abc)(.|\n))*$
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 22782934
Thanks for the question and the points.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 45
regx  exclude  pattern 6 43
String array comparison 4 34
Adding multiple JVM environments to RedHat 6 7 24
I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question