Solved

Regular Expression String Search

Posted on 1998-12-23
4
159 Views
Last Modified: 2010-05-03
I want to search as string using wildcard characters such as '*' and "#" and be able to highlight the text that was found.  For example I want to search all the text in a rich text box for the reg. expression "*explore*" and highlight the parts of the text that match this criteria. Is there any easy way to do this in VB?
0
Comment
Question by:jmalcolm
  • 2
4 Comments
 

Author Comment

by:jmalcolm
ID: 1452283
Edited text of question
0
 
LVL 4

Expert Comment

by:offir_a
ID: 1452284
hi there!
i used in my app. the InStr():
you need to give for the function: 1: String expression being searched, 2: String expression sought 3: you can Specify the type of string comparison. (binary - "a" -> "a", text - "a" -> "a" / "A")
This example uses the InStr function to return the *position* of the first occurrence of one string within another.
Dim SearchString, SearchChar, MyPos
SearchString ="XXpXXpXXPXXP"      ' String to search in.
SearchChar = "P"      ' Search for "P".
      
' A textual comparison starting at position 4. Returns 6.
MyPos = Instr(4, SearchString, SearchChar, 1)      
      
' A binary comparison starting at position 1. Returns 9.
MyPos = Instr(1, SearchString, SearchChar, 0)
      
' Comparison is binary by default (last argument is omitted).
MyPos = Instr(SearchString, SearchChar)      ' Returns 9.
      
MyPos = Instr(1, SearchString, "W")      ' Returns 0.
      
no, when you got the position and you know the length of the string you want, ( use the "len()" func. ), you can do whatever you'd like to do with it in the rich text box.
0
 

Author Comment

by:jmalcolm
ID: 1452285
The instr function doesn't let me use wildcard characters such as * and #, the LIKE function will return me a boolean as to whether or not these appear in a given string, but I want to be able to search and replace based on these regular expressions.


0
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 50 total points
ID: 1452286
You can do a bolean-like search using LIKE. Lets say you have a variable named S$ with the text. First, you make sure the expression is in S$ using LIKE. Then, you use Left/Right/Mid to split it to 2, and check the first part. IF it was found there, you keep splitting it until you find an exact match. If it wasn't found in the first part, you do the same with the second part
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now