?
Solved

Regular Expression String Search

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

762 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