Regular expression problem.

    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
LVL 26
Tomas Helgi JohannssonAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
word1|word2|word3
0
 
Tomas Helgi JohannssonAuthor Commented:
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
 
CEHJCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Tomas Helgi JohannssonAuthor Commented:
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
 
CEHJCommented:
Database would be OK, but harder to change and certain characters could be a problem
0
 
CEHJCommented:
>>
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
 
objectsConnect With a Mentor Commented:
have you list of words instead be a list of patterns. that would give u the flexibility to handle your matching as required.
0
All Courses

From novice to tech pro — start learning today.