Hot answers tagged string-manipulation
14
It's easy to search if you break it down:
Regex Meaning Mathematica command
-------------------------------------------------
\w word character WordCharacter
{2,3} repeat 2 to 3 times Repeated[..., {2, 3}]
Combine it and use as:
StringMatchQ[{"a", "ab", "abc", "abcd"}, Repeated[WordCharacter, {2, 3}]]
(* {False, True, True, ...
10
A couple of details:
Restricting code__ to NumberString will prevent it from being greedy (else it might stop only at the second ))
You need to wrap the entire pattern (which is what we want to repeat) in parentheses to respect the precedence of the .. operator.
The following pattern works:
StringCases[text1, ("ICD-9-CM " ~~ code : NumberString) .. ...
7
But I would like to know the positions of "Element 1" and "Element 2"...
You can still use Position[]; things are a little more elaborate, though, due to the strings:
Position[list, s_String /; StringMatchQ[s, "El*"]]
{{4}, {7}}
Extract[list, %]
{"Element 1", "Element 2"}
6
You could simply find the shortest match:
StringCases[text1, "(ICD-9-CM " ~~ Shortest[code__] ~~ ")" :> code]
{"268.9", "268.9"}
If it is possible that there is additional space or other characters a combination may be more robust:
text2 = " A Vitamin D Deficiency (ICD-9-CM 268.9) (ICD-9-CM: 268.9) 09/11/2015 01 ";
StringCases[text2, ...
6
I'd say this is either a programming or a documentation bug.
The documentation for WordCharacter says:
WordCharacter matches any character for which either LetterQ or DigitQ yields True. »
Well, WordCharacter clearly doesn't consider alpha a letter:
StringMatchQ["α", WordCharacter]
False
but LetterQ does:
LetterQ["α"]
True
A ...
4
Style[..] is not a string. Convert it to string by using StandardForm format to preserve style information:
dollarWon := 100
"(" <> ToString[
Style["$" <> ToString[dollarWon],
If[dollarWon >= 0, Darker[Green], Red]], StandardForm] <> ")"
4
I have partial success in splitting Greek text:
greek = ExampleData[{"Text", "HomerOdysseyGreek"}]
Style[StringTake[greek, 100], FontFamily -> "Times"]
Style[StringSplit[StringTake[greek, 100], " "], FontFamily -> "Times"]
3
Might be better to use Table[] instead, so you can still use the processed images later:
girls = Table[ImageEffect[ExampleData[{"TestImage", img}], "Charcoal"],
{img, {"Elaine", "Lena", "Tiffany"}}]
so for instance girls[[2]] gives Lenna in charcoal.
For your specific example,
Table[ColorNegate[ToExpression["name" <> ToString[i]]], ...
2
Maybe this
LongestCommonSubsequencePositions["DOLORE","LOREM"]
LongestCommonSubsequencePositions[{"D","O","L","O","R","E"},{"L","O","R","E","M"}]
{{3,6},{1,4}}
{{3,6},{1,4}}
LongestCommonSubsequencePositions["DOLORE", "LOREMIJKLMKJLKJLKJLJK"]
LongestCommonSubsequencePositions[{"D", "O", "L", "O", "R", "E"}, Characters@"LOREMIJKLMKJLKJLKJLJK"]
{{1,4},{3,6}}
...
2
Yes, you need to escape a * character in a string pattern because it's a wildcard. To escape it, just prepend a backslash to it. Remember that to insert a backslash in a Mathematica string, you need to type two backslashes:
StringMatchQ["*", "\\*"]
(* => True *)
1
If you know that the code you are searching for is a number, then I think the suggestions to use patterns which recognize such number strings are your best bet. For completeness I wanted to show another way which I think is a useful standard approach for such tasks and will work even when you can't make such a premise. The idea is to simply only let code ...
1
I think I've found an answer to my own question.
Bypassing the difficulties of replacing d to $\mathrm{d}$, the following code constructs the intended TeX-form directly.
SetAttributes[integralTeXForm, HoldAll]
integralTeXForm[expr_, arg__] := Module[{temp, var, add},
add = If[Length@# == 3, "_" <> #[[2]] <> "^" <> #[[3]] <> " ", ...
Only top voted, non community-wiki answers of a minimum length are eligible


