Items tagged with stringtools stringtools Tagged Items Feed

I am looking to return all the substrings of a string that match a particular pattern (regexp). This is a very common text processing operation.

StringTools[RegMatch] returns boolean about whether the given pattern exists somewhere in the string. That's a start, but it is not efficient to hunt around for where the match is in order to extract the characters.

StringTools[Search] and [SearchAll] can return position information, but they work on exact matches of the pattern space, not on regular expressions. I could pre-generate all the possible matching sequences of up to some length and search for those exactly, but that is inconvenient at best and pretty much useless if there is a .* or .+ in the regular expression (as the space of potential matches grows exponentially.)

StringTools[RegSub] can be used to find one match by using something like ".*(REALPATTERN).*" = "\1" but since this does not extract any position information, one would at the very least then have to StringTools[Search] of the exact match to determine the position, then take a substring of the original string, and continue searching. And if you are going to do that, you might as well just use StringTools[RegMatch] with an optional third argument of a symbol to return the matched characters, instead of fooliing around with deleting everything else using RegSub.

Have I overlooked a possibility?

Example of use:

I would like to search "variable %1 needs to be of the form %3+2.9 in order to use routine %2 to find the fizturl", extracting the "%1", "%3", "%2". This would be regular expression "%[0-9]+". Notice that there might be other digits in the string that I do not want to extract, so I cannot just search for digits. I also cannot just remove all characters "[^0-9%]" as that would leave digits and would, for example, merge together the %3+2.9 into %329 leaving post-processing to extract the true pattern matches.

For what I am doing at the moment, I do not need to know the positions those occured at, just the matches.

Strings := {"buffalo", "zebra", "aardvark", "aardwolf", "anteater", "antelope", "bumblebee"};
{"buffalo", "zebra", "aardvark", "aardwolf", "anteater",

"antelope", "bumblebee"}
CP := {seq(seq(StringTools:-Take(x, StringTools:-CommonPrefix(x, y)), x in Strings), y in Strings)};
P := table(map(proc (x) options operator, arrow; x = "" end proc, Strings));
for x in CP do for y in `minus`(CP, {x}) do if `and`(StringTools*IsPrefix(y, x), `implies`(assigned(P[x]), StringTools*IsPrefix(P[x], y))) then P[x] := y end if end do end do;
Error, cannot determine if this expression is true or false: StringTools*IsPrefix("a", "")


Hi I tried to apply these command in maple to see hoe cluster graphic after that can work .. but i face this problem ,


I am a begginer in maple working on it for a term paper to demonstrate it is ability to view the cluster analysis .


if u have any benefcial resources I ll be so happy.


thanks very much

We have two texts in a certain language, represented as Maple  strings,  e. g.
"die einkommen der landwirte sind fuer die abgeordneten ein
buch mit sieben siegeln um dem abzuhelfen muessen dringend alle
subventionsgesetze verbessert werden" and
"die steuern auf vermoegen und einkommen sollten nach meinung
der abgeordneten nachdruecklich erhoben werden dazu muessen die
kontrollbefugnisse der finanzbehoerden dringend verbessert werden".
We have to find the maximal common subsequence of the words in the both texts,
i.e. "die  einkommen der abgeordneten muessen dringend verbessert werden" for
the above. If there are a few such ones, then only one is enough. How to program
that by SringTools and/or EssayTools in maximum efficient way? A compiled procedure is welcome.

 i have big problem, i dont know, how to add 0 in front.
firstly, i convert decimal to binary and  then i convert to string

but, how i add some 0 in front??
for exmple below..


i want to look like 7 bit

i dont know how to count all digit, and how to add some 0 to front , and also have 7 bit?

I have a message, "I Didn't See That Double Rainbow!" and i want to encrypt it by making all the characters UpperCase first and removing all punctuation. I used IsUpper to remove the punctuation. Now I want to separate my new scrambled message into BLOCKS OF 5 LETTERS SEPARATED BY SPACES. Any ideas on how to do that using the "printf" command?



Several months ago, I'd posted a two-letter-words quiz and a two-to-make-three quiz meant for fans of the Scrabble game. Here is a third worksheet that tests your ability to find anagrams of seven-letter words. The worksheet is structured around six-letter stems and the lists of seven-letter...

In a string, how can I find a letter of both upper and lower case?

ie/ something like

StringTools[SearchAll]("h" and "H" , string)

Some time ago, I posted a two-letter-words quiz for Scrabble players. That one is particularly useful to beginner players wanting to increase their scoring opportunities. I've created another worksheet for those looking for a greater challenge. This one tests your knowledge of the three-letter words that can be created from the valid two-letter words. Enjoy!

Many years ago, I played Scrabble competitively. One of the first things a beginner tournament player should do is learn the two-letter word list. Recently, I created a worksheet that tests your knowledge of all the valid two-letter words accepted in official tournament play in North America. The worksheet makes extensive use of the StringTools package which has terrific tools for manipulating words.

The worksheet link is below if you'd like to try it out, and I'll...


I need a procedure to unjumble a series of 9 letters into discernable 4 to 9 letter words. each letter can only be used once and it needs to include a given letter in each word. eg IOCMRELAE, and include R in each word

Acer did a similar thing a while back, but in this case it needs to tell it to permute 9 letters, then 8,....,then 4 (each including letter R).

 >with(StringTools): with(PatternDictionary):
>bid:= Create(`builtin`):


I expect the first call to Length to return a value of 63.  The backslashes are being ignored.  Is this a "feature", or is the Length command not behaving as it should?

Another feature added to Maple 15 partially in response to the MaplePrimes forums is the new/improved ?HTTP package.  It provides one-step commands for fetching data from the web: much simpler than using the ?Sockets package directly. In most cases, the command ?HTTP,Get is what you would use:

 (s, page, h) := HTTP:-Get(""):

The above fetches the HTML source of a page from Wikipedia and stores it as a string 'page'. The other two outputs are 's', and integer HTTP status code and 'h' a table of the headers returned in the HTTP response from the server.  Compare this to the amount of code needed to fetch data in my Baby Names application for Maple 12, for example.

I was recently asked a question on using regular expressions with ?type , and I thought it was interesting enough, to share here.

Page 1 of 1