Solved

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

Posted on 2014-11-17
11
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40448637
(?<!\[)[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
ID: 40448649
Thanks for responding.  I mean immediately preceded and vb.net.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40448650
Also, why would "f/" not satisfy the criteria? In other words, why does "/d" match, but "f/" does not?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40448658
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
ID: 40448659
That was a typo. f/ should also match.  I'm sorry I was writing the example on the fly and missed my mistake.
0
 

Author Comment

by:NevSoFly
ID: 40448665
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 75

Accepted Solution

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

Try:

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

Open in new window

0
 
LVL 75

Expert Comment

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

Author Comment

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

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
ID: 40448707
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
ID: 40448720
Thanks for your help and suggestion.  I will start using regexhero from now on.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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,…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…

756 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