Solved

Regular expression problem.

Posted on 2007-04-11
7
199 Views
Last Modified: 2010-03-31
    Hi!

I need some help with Regular Expressions.
Suppose I have a list/array of words and I want to check a very long string (like a string from an textarea on a webpage)
if any pattern of a particular word in the list/array is in that string.
How can I do it in a fast an efficient way ?

Regards,
  Tomas Helgi
0
Comment
  • 3
  • 2
  • 2
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
word1|word2|word3
0
 
LVL 24

Author Comment

by:Tomas Helgi Johannsson
Comment Utility
So I would do something like

Pattern patt = Pattern.compile("word1|word2|word3");
Matcher m = patt.matcher(textareastring);
      while (m.find()) {
        //   do stuff
      }

Now if I would like to check if my name is in that string in some obscure way like
  ....T/oYm/As... but in the array of checklistwords my name would be written normally like Tomas

How would I do that ?

Regards,
  Tomas Helgi
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You would be better keeping the word list in a text file. Iterate the list and check each for matches - that's all the re engine would do anyway
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 24

Author Comment

by:Tomas Helgi Johannsson
Comment Utility
I was thinking of having the words in a database table and iterate through that list. But I'm wondering if a text that includes the word "T/oYm/As" would match my word in the table that would be written like "Tomas" ?
Or do I have to set up a pattern like "*T*o*m*a*s*" ?

Regards,
  Tomas Helgi
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Database would be OK, but harder to change and certain characters could be a problem
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>
But I'm wondering if a text that includes the word "T/oYm/As" would match my word in the table that would be written like
>>

No. You'd need to change the pattern
0
 
LVL 92

Assisted Solution

by:objects
objects earned 500 total points
Comment Utility
have you list of words instead be a list of patterns. that would give u the flexibility to handle your matching as required.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 42
countX 22 69
bitbucket vs gitbucket 3 29
Non-recursive backtracking, using a stack 1 48
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

744 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

15 Experts available now in Live!

Get 1:1 Help Now