Solved

Regular Expression String Search

Posted on 1998-12-23
4
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

691 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