Solved

Can't get the character set of [^]] to match "]" in regex (([^[])(-?\w)/)|(/(-?\w)([^]])).

Posted on 2014-11-17
11
147 Views
Last Modified: 2014-11-17
I'm trying to create a regex that only matches when:
An alphanumeric character that is not preceded by "[" but is followed by "/"
and a "/" & an alphanumeric character when there isn't a "]" in front of it.

for example:
1[ts/tty]/a..[a/bravo] ntf/dt; c/[antenna/board] --->  should match /a, /d and c/

So far I have (([^[])(-?\w)/) ---> this matches /d and c/ but not /a.  I have tried (([^[])(-?\w)/)|(/(-?\w)([^]])) but can't get the character set of [^]] to match "]".
0
Comment
Question by:NevSoFly
  • 6
  • 5
11 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
(?<!\[)[a-zA-Z0-9](?=/)|(?<!\])/[a-zA-Z0-9]

Open in new window


** edit

Does "preceded" mean "immediately preceded," or just "preceded"? Also, what programming language or text editor are you using?
0
 

Author Comment

by:NevSoFly
Comment Utility
Thanks for responding.  I mean immediately preceded and vb.net.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Also, why would "f/" not satisfy the criteria? In other words, why does "/d" match, but "f/" does not?
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
And I do not understand why "/a" matches. According to your criteria:

"/" & an alphanumeric character when there isn't a "]" in front of it.

But there most assuredly is a ] in front of the "/a".
0
 

Author Comment

by:NevSoFly
Comment Utility
That was a typo. f/ should also match.  I'm sorry I was writing the example on the fly and missed my mistake.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:NevSoFly
Comment Utility
I'm doing a terrible job at explaining what I want. Sorry.  A / and alphanumeric character or an alphanumeric character and / should always match unless they are inside a set of [].
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
That makes a bit more sense  = )

Try:

(?<!\[[^]]+)(/[a-zA-Z0-9]|[a-zA-Z0-9]/)(?![^[]+\])

Open in new window

0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
I made an edit to the above just now. Forgot one small character!
0
 

Author Comment

by:NevSoFly
Comment Utility
I am using regexr.com to test the patterns out but your suggestion didn't match anything.
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
Comment Utility
Try at http://regexhero.net/tester/

regexr.com isn't a .NET-based regex engine, and the constructs I used above only work in .NET (and one or two other regex engines).
0
 

Author Closing Comment

by:NevSoFly
Comment Utility
Thanks for your help and suggestion.  I will start using regexhero from now on.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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,…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

744 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

8 Experts available now in Live!

Get 1:1 Help Now