473,382 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to find words from .txt file using specific pattern

2
It's my first post here, so hi all.
Anyway, I am trying to work this out, but can't do this alone. I have a specific line of text, I already replaced it with something more user-friendly using this piece of code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $algorytm = ",,D-,,R,-,,T,-,P,,-F,,,¤,P,,-,I,,-,,,F-,,,E¤,,,G-,,T,-,,S,-O,,,-,,E,¤,,,E,-D,,,,-,P,,,-R,,,,-,,N,,¤,,,S,-,,A,,-,,L,,¤,,,,M-,,,A,-,,,S,-,,F,,-,,,B,¤,,,,G-,,,T,-,E,,,";
  4.  
  5. $algorytm2 = str_replace(",", "?", $algorytm);
  6. $algorytm3 = str_replace("¤", "-", $algorytm2);
  7. $algorytm4 = str_replace("-", "<br>", $algorytm3);
  8. echo $algorytm4;
  9.  
  10. ?>
  11.  
The result is here: http://p.netserwer.pl/words/
The pattern itself always contains 30 lines that contains words made from 3, 4 or 5 letters. There is always only 1 letter assigned, the ? are wildcards and anything can be placed here. What do I need ? - example:

??D RED
??R? BIRD
??T? BITS

I am trying to assign a word to every line next using the pattern where ??D is any 3-letters word that ends with D etc. I have also made wordlists:
http://p.netserwer.pl/words/3.txt
http://p.netserwer.pl/words/4.txt
http://p.netserwer.pl/words/5.txt

To be honest, I am not a good programmer and have no idea how to make it. Any help or advice will be appreciated.
Jul 22 '10 #1
2 2735
dlite922
1,584 Expert 1GB
So what you have to do is convert your 30 or so patterns to expressions. Then for every line in your words file check to see if any of the words match any of the pattern.

Here's an example of a regular expression for one of your patterns:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if(preg_match('[A-Z][A-Z]D',$word,$match)
  3. {
  4.   echo $match[0];
  5. }
  6.  
  7.  
so just replace your question marks with [A-Z], put it in pregmatch function and compare to each of your words in your word file.

I see each of your word file contains 3 letter, 4-letter, and 5-letter words, so I guess you should organize your patterns this way too: compare 4 letter patterns with the 4.txt file, etc.

Good luck,


Dan
Jul 22 '10 #2
firian
2
This is what I get so far: http://p.netserwer.pl/words/

Sample patterns to input in textform:
,,D-,,R,-,,T,-,P,,-F,,,¤,P,,-,I,,-,,,F-,,,E¤,,,G-,,T,-,,S,-O,,,-,,E,¤,,,E,-D,,,,-,P,,,-R,,,,-,,N,,¤,,,S,-,,A,,-,,L,,¤,,,,M-,,,A,-,,,S,-,,F,,-,,,B,¤,,,,G-,,,T,-,E,,,

It's just a sample of 30 patterns, they will change, so I can't code anything for specific pattern. That's why I need something that will not be defined for specific pattern like ??D - but for everything that I input.

//edit
I found this: http://www.thewordfinder.com/classic/crossword.php
I need something similar, you input 1 pattern here and get matching words. I need same thing for list of 30 patterns, where I will have 1 word matched.
Jul 22 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ruby Tuesday | last post by:
In a directory, how to find an image file with part of its filename is known and the file extension could be one of the following(jpg, tiff, bmp,png). The filename always begin between 1 to 3...
2
by: Sam Kon via .NET 247 | last post by:
Can any one of you let me know, how can I replace a pattern in an html file using C#? I have the contents of the html file stored in a string. I just need to replace some of the elements which have...
5
by: Paula | last post by:
Hi !! I have to find some words in a string. I can use string.IndexOf, LastIndexOf, etc, but they are case sensitive. And there is another problem : If I found the word, I have to get three...
8
by: Michael | last post by:
I am running a web server (IIS) on Windows 2003 SP 1. My ASP.NET C# applications run fine. However, my application is a combination of Classic ASP and C#. For some reason when you attempt to...
8
by: writeanand | last post by:
How can I count the frequency of words in a ASCII File using STL? a) I dont know what words will be found in the file b) The max number of occurrences is 10,000 per word (in case that matters) ...
4
by: writeanand | last post by:
How can I count the frequency of words in a ASCII File using STL? I dont know what words will be found in the file ahead of time. I dont want to use any classes, just a simple program wd do. ...
3
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I...
13
by: Albert | last post by:
Hi I'm using the lcc compiler for win32. I tried compiling a program but there's an error stating: "cpp: Can't open input file clrscr()" I don't get it - I've included <tcconio.h>. (strange why...
3
by: markcash | last post by:
I have a web application where I am displaying the current inmate population for the county jail. Part of the information that I display is the mugshot. Unfortunately, they have changed the way...
0
by: FredSovenix | last post by:
Can anybody provide instruction or examples on how to access the noise words file using T-SQL? I want to be able to adjust the users' search string by eliminating the noise words, but if the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.