[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Regular Expression String Search

Posted on 1998-12-23
4
Medium Priority
?
166 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 100 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month17 days, 20 hours left to enroll

830 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