Tag Info

New answers tagged

0

Regular Expressions This is typically solved with pattern matching. You specify a pattern by creating a regular expression (or short regex) using RegularExpression. text1=" A Vitamin D Deficiency (ICD-9-CM 268.9) (ICD-9-CM 268.9) 09/11/2015 01 "; StringCases[text1,RegularExpression["\\(ICD-9-CM\\s*([0-9\\.]+)\\)"]:>"$1"] yields: {268.9,268.9} ...


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 ...


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, ...


5

With RegularExpression you could use: text1 = " A Vitamin D Deficiency (ICD-9-CM 268.9) (ICD-9-CM 268.9) 09/11/2015 01 "; StringCases[text1,RegularExpression@"\\(ICD-9-CM (\\d+(\\.)?(\\d+)?)\\)"-> "$1"]


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"}


3

A possibility: Cases[list, x_String /; StringMatchQ[x, "El*"]] {"Element 1", "Element 2"}


5

Select[list, StringMatchQ[ToString@#, "El" ~~ ___] &] {"Element 1", "Element 2"}


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}} ...


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]] <> " ", ...


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, ...


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

The problem is that Do doesn't return anything so you just need to prepend Print to your function to see the result: Do[Print@ColorNegate[ToExpression[StringJoin["name", ToString[i]]]], {i, 14, 20}]


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] <> ")"


3

I think you may be better of using Row in this case, which lets you show arbitrary objects in a row, like so: dollarWon = 100 Row[{ "(", Style[ "$" <> ToString[dollarWon], If[dollarWon >= 0, Darker[Green], Red] ], ")" }]


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"]


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 ...



Top 50 recent answers are included