Solved

regex exclusion

Posted on 2008-10-22
4
564 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
Comment Utility
 Pattern re = Pattern.compile("^(?:(?!abc).)*$",Pattern.DOTALL);
0
 

Author Comment

by:acclimate
Comment Utility
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
Comment Utility
(?s)^(?:(?!abc).)*$

or:

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

or:

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

Expert Comment

by:ddrudik
Comment Utility
Thanks for the question and the points.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now