Solved

Regular expression problem.

Posted on 2007-04-11
7
233 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 96
servlet and mdb, jms error 1 55
jsp error 6 43
IBM TS2900 (3572) Tape Autoloader Java? 12 55
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…

735 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