Solved

Regular expression problem.

Posted on 2007-04-11
7
238 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
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 18889002
word1|word2|word3
0
 
LVL 25

Author Comment

by:Tomas Helgi Johannsson
ID: 18889192
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
ID: 18889439
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 25

Author Comment

by:Tomas Helgi Johannsson
ID: 18889495
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
ID: 18889518
Database would be OK, but harder to change and certain characters could be a problem
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18889528
>>
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
ID: 18889608
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse console opening separately 2 50
Java basic valueOf question 1 51
java mysql insert application 14 68
Website checklist for browser compatibility? 2 57
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

751 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