Solved

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

Posted on 2014-11-17
11
150 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 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java rename file(s) question - regular expressions 4 57
plusOut java challenge 40 174
VBA Test For Valid Number Format 6 59
Powershell String Parsing with Regular Expression 19 50
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…
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…

785 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