[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

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

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
NevSoFly
Asked:
NevSoFly
  • 6
  • 5
2 Solutions
 
käµfm³d 👽Commented:
(?<!\[)[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
 
NevSoFlyAuthor Commented:
Thanks for responding.  I mean immediately preceded and vb.net.
0
 
käµfm³d 👽Commented:
Also, why would "f/" not satisfy the criteria? In other words, why does "/d" match, but "f/" does not?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
käµfm³d 👽Commented:
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
 
NevSoFlyAuthor Commented:
That was a typo. f/ should also match.  I'm sorry I was writing the example on the fly and missed my mistake.
0
 
NevSoFlyAuthor Commented:
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
 
käµfm³d 👽Commented:
That makes a bit more sense  = )

Try:

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

Open in new window

0
 
käµfm³d 👽Commented:
I made an edit to the above just now. Forgot one small character!
0
 
NevSoFlyAuthor Commented:
I am using regexr.com to test the patterns out but your suggestion didn't match anything.
0
 
käµfm³d 👽Commented:
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
 
NevSoFlyAuthor Commented:
Thanks for your help and suggestion.  I will start using regexhero from now on.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now