$word = 'educated'; $word =~ s/ed$//;
The $ anchors the pattern to the end of the string.
-sauoq
"My two cents aren't worth a dime.";
| [reply] [d/l] [select] |
| [reply] |
Just thought I'd explain the previous regexes a little. The ^ represents the start of the string with $ represents the end of the string. The .* (greedy) part will match as many characters it can before 'ed'. On the other hand a .*? is non-greedy and will match as few as possible characters, in this case zero, before 'ed'.
Also be sure to look at perldoc perlre.
Hope this helps a little more.
| [reply] |
hehe, Sauoq beat me to it, really though what are you trying to do? If not give a example that is more specific to your real issue if this does not work.. If you are just looking to stem words it may be worthwhile to look at Lingua::Stem. If you are looking to only change words that end in "ed" and follow the "leave the e" rule just do s/^(.*)ed/$1e/i
-Waswas
| [reply] [d/l] |
Well, I basically am trying to create a spell checker for the win32 platform, seeing as how there seems to be a noticeable lack them for win32.
I have looked at Lingua::Stem, and am actually using Lingua::EN::Infinitive to determine if a word is at least formed correctly. The problem occurs when I am trying to make reasonble suggestions to the user. My approach, rather than using the brute-force, mass dictionary approach, is to try to create a more intelligent search. So, if a word is not in the dictionary, and not well formed, it attempts to strip any prefixes and suffixes, and find the 'root', and then do a Double Metaphone on the 'root' (rewrote Double Metaphone for under win32), and find any words that are close, and then attempt to reattach the prefixes and suffixes. (Will have to insert grammatical checking at a later point.) So, in order to do that, I need to strip them. Prefixes are easy, suffixes can get a little tricky.
So, if anyone knows of a good (American English) conjugating module that will work under win32, or will work with minimal rewriting, please let me know!
| [reply] |
Have you thought about making a aspell wrapping mod? http://prdownloads.sourceforge.net/aspell/aspell-.33.5-win32-i386.zip is the aspell bin for win32 systems, and it should run much faster than a perl based solution (as long as you develop it to load whole files not exec for each word) you may want to look at Lingua::Ispell for a baseline (I think aspell has been developed to behave very similar to ispell) I am not sure how much of a mod that will take to get it to work with aspell though. But none of this matters if your entire goal is to make a perl only spell checker module..
-Waswas
| [reply] |