Solved

regex exclusion

Posted on 2008-10-22
4
565 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 39
Java - Why doesn't this JFrame work 3 45
Regex code:separate email:ip from email:pass ? 6 48
Spring Framework HTTPSession management 1 24
by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

864 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

19 Experts available now in Live!

Get 1:1 Help Now