Solved

Regular Expression String Search

Posted on 1998-12-23
4
158 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

708 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