We help IT Professionals succeed at work.

vb.net REGEX

Hello, all.

I have these two commands

Example insert

{Something here} {{Something else here}}

Open in new window


Dim Regex2 As Regex = New Regex("\{.*?\}")
Dim Regex4 As Regex = New Regex("\{{.*?\}}")

Open in new window


They do not produce any errors, however.
The single { }
Will insert into the database for the {{ }}
In the database, you will see
{Something here}

Open in new window

With the curly brackets around it.

How can I distinguish between the two commands, so that only the double curly's will insert into its column, and the single curly will only insert into its column?

Thanks
Wayne
Comment
Watch Question

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
Try this:

Dim Regex2 As Regex = New Regex("(?<!\{)\{(?!\{).*?(?<!\})\}(?!\})")
Dim Regex4 As Regex = New Regex("\{{.*?\}}")

Open in new window


»bp
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:

Unfortunately, it does not work.
Still inserts the   {Something here}

Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:

IT WORKED!!!

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Maybe I didn't understand.  I thought you wanted Regex2 to match the {Something here} but not the {{Something else here}}.  That's what the regex I posted does do.

Maybe I need to understand better what you're doing and how you're using those patterns...


»bp
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Okay, great, our posts crossed.


»bp
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:

Yea, I was thinking it might over post you.
All good.
To be honest, I think the original would have worked as well.
I noticed in my code, that I had the wrong variable called, and I was using the single Curly variable and not the double curly variable. But either way, it works great.

Wayne