mzurita
mzurita

Reputation: 690

Regular Expression: Searching the pattern "(space)word(space)" (Vb.net)

I am trying creating a MS-Access database programmatically from Sqlite sentences in Visual Basic 2008, and as word "password" is a field reserved word, I have to replace it by "[password]" and it works fine. The problem is, there is field names with "password" word embedded as "2nd_password" or "password_3rd" for example, in this case doesn't necessary replace "password"

So I am searching the following results:

 password -> [password]
 2nd_password -> 2nd_password
 password_3rd -> password_3rd

I've tried searching the pattern "(space)password(space)" but it doesn't work.

 Regex.Replace(query, ":bpassword:b", " [password] ")

Thanks in advance.

Upvotes: 0

Views: 148

Answers (2)

Sabuj Hassan
Sabuj Hassan

Reputation: 39365

Please try this one as well apart from \b:

(?<!\w)password(?!\w)

Thins one is checking a non alphanumeric(a-z A-Z 0-9 _) characters on left and right side of the password.

Upvotes: 1

OGHaza
OGHaza

Reputation: 4795

Just looking here it seems like in VB you still use \b not :b

 Regex.Replace(query, "\bpassword\b", " [password] ")

Upvotes: 1

Related Questions