For the latest updates and corrections to this manual: visit reference.wolfram.com For information on additional copies of this documentation: visit the Customer Service website at www.wolfram.com/services/customerservice or email Customer Service at info@wolfram.com Comments on this manual are welcomed at: comments@wolfram.com Content authored by: Oyvind Tafjord Printed in the United States of America. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 2008 Wolfram Research, Inc. All rights reserved. No part of this document may be reproduced or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright holder. Wolfram Research is the holder of the copyright to the Wolfram Mathematica software system ("Software") described in this document, including without limitation such aspects of the system as its code, structure, sequence, organization, look and feel, programming language, and compilation of command names. Use of the Software unless pursuant to the terms of a license granted by Wolfram Research or as otherwise authorized by law is an infringement of the copyright. Wolfram Research, Inc. and Wolfram Media, Inc. ("Wolfram") make no representations, express, statutory, or implied, with respect to the Software (or any aspect thereof), including, without limitation, any implied warranties of merchantability, interoperability, or fitness for a particular purpose, all of which are expressly disclaimed. Wolfram does not warrant that the functions of the Software will meet your requirements or that the operation of the Software will be uninterrupted or error free. As such, Wolfram does not recommend the use of the software described in this document for applications in which errors or omissions could threaten life, injury or significant loss. Mathematica, MathLink, and MathSource are registered trademarks of Wolfram Research, Inc. J/Link, MathLM, .NET/Link, and webMathematica are trademarks of Wolfram Research, Inc. Windows is a registered trademark of Microsoft Corporation in the United States and other countries. Macintosh is a registered trademark of Apple Computer, Inc. All other trademarks used herein are the property of their respective owners. Mathematica is not associated with Mathematica Policy Research, Inc. Contents Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 General String Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 RegularExpression versus StringExpression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 String Manipulation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 StringMatchQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 StringFreeQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 StringCases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 The Overlaps Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 StringPosition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 StringCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 StringReplace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 StringReplaceList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 StringSplit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 For Perl Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 m/.../ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 s/.../.../ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 split(...) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 tr/.../.../ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Some Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Highlight Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 HTML Parsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Find Money . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Find Text in Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Tips and Tricks for Efficient Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 StringExpression versus RegularExpression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Conditions and PatternTests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Avoid Nested Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Avoid Many Calls to a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Rewrite General Expression Searches as String Searches . . . . . . . . . . . . . . . . . . . . . . . 32 Implementation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Introduction The general symbolic string patterns in Mathematica allow you to perform powerful string manipu - lation efficiently. What follows discusses the details of string patterns, including usage and implementation notes. The emphasis is on issues not mentioned elsewhere in the help system. At the heart of Mathematica is a powerful language for describing patterns in general expres- sions. This language is used in function definitions, substitutions, and searches, with constructs like x_, a b, x .., and so on. In[1]:= MatchQ[{a, b, c, d}, {___, x_, x_, ___}] Out[1]= False In[2]:= MatchQ[{a, b, c, c, d}, {___, x_, x_, ___}] Out[2]= True In[3]:= Cases[{a, 3, 4, b, c, 8}, _Integer] Out[3]= {3, 4, 8] A Mathematica string pattern uses the same constructs to describe patterns in a text string. You can think of a string as a sequence of characters and apply the principles of general Mathe- matica patterns. In addition there are several useful string-specific pattern constructs. In[4]:= StringMatchQ["abcd", ___ ~~ x_ ~~ x_ ~~ ___] Out[4]= False In[5]:= StringMatchQ["abccd", ___ ~~ x_ ~~ x_ ~~ ___] Out[5]= True In[6]:= StringCases["a34bc8", DigitCharacter] Out[6]= {3, 4, 8] Regular expressions can be used as an alternative way to specify string patterns. These tend to be more compact, but less readable. In[7]:= StringMatchQ["abcd", RegularExpression[".+(.)\\1.+"]] Out[7]= False In[8]:= StringMatchQ["abccd", RegularExpression[".+(.)\\1.+"]] Out[8]= True In[9]:= StringCases["a34bc8", RegularExpression["\\d"]] Out[9]= {3, 4, 8] Here is a list of several functions that recognize string patterns. StringMatchQ["s",patt] test whether s matches patt StringFreeQ["s",patt] test whether s is free of substrings matching patt StringCases["s",patt] give a list of the substrings of s that match patt StringCases["s",lhs->rhs] replace each case of lhs by rhs StringPosition["s",patt] give a list of the positions of substrings that match patt StringCount["s",patt] count how many substrings match patt StringReplace["s",lhs->rhs] replace every substring that matches lhs StringReplaceList["s",lhs->rhs] give a list of all ways of replacing lhs StringSplit["s",patt] split s at every substring that matches patt StringSplit["s",lhs->rhs] split at lhs, inserting rhs in its place Functions that support string patterns. General String Patterns A general string pattern is formed from pattern objects similar to the general pattern objects in Mathematica. To join several string pattern objects, use the StringExpression operator --. In[10]:= FullForm["a" ~~ _] Out[10]//FullForm= StringExpression["a", Blank[]] StringExpression is closely related to StringJoin, except nonstrings are allowed and lists are not flattened. For pure strings, they are equivalent. In[11]:= "aa" ~~ "bbb" ~~ "c" Out[11]= aabbbc The list of objects that can appear in a string pattern closely matches the list for ordinary Mathe- matica patterns. In terms of string patterns, a string is considered a sequence of characters, that is, "abc" can be thought of as something like String[a, b, c], to which the ordinary pat- tern constructs apply. The following objects can appear in a symbolic string pattern. 2 Advanced String Patterns "string" a literal string of characters _ any single character __ any substring of one or more characters ___ any substring of zero or more characters x_ , x__ , x___ substrings given the name x x:pattern pattern given the name x pattern.. pattern repeated one or more times pattern... pattern repeated zero or more times patt 1 ,patt 2 , or patt 1 patt 2 a pattern matching at least one of the patt i patt/;cond a pattern for which cond evaluates to True pattern?test a pattern for which test yields True for each character Whitespace a sequence of whitespace characters NumberString the characters of a number DatePattern[spec] the characters of a date charobj an object representing a character class (see below) RegularExpression["regexp"] substring matching a regular expression StringExpression[] an arbitrary string expression The following represent classes of characters. {c 1 ,c 2 ,] any of the "c i " Characters["c 1 c 2 "] any of the "c i " CharacterRange["c 1 ","c 2 "] any character in the range "c 1 " to "c 2 " HexadecimalCharacter hexadecimal digit 09, af, AF DigitCharacter digit 09 LetterCharacter letter WhitespaceCharacter space, newline, tab or other whitespace character WordCharacter letter or digit Except[p] any character except ones matching p The following represent positions in strings. Advanced String Patterns 3 StartOfString start of the whole string EndOfString end of the whole string StartOfLine start of a line EndOfLine end of a line WordBoundary boundary between word characters and others ExceptWordBoundary anywhere except a word boundary The following determine which match will be used if there are several possibilities. Shortest[p] the shortest consistent match for p Longest[p] the longest consistent match for p (default) Some nontrivial issues regarding these objects follow. The _, __, and ___ wildcards match any characters including newlines. To match any character except newline (analogous to the "." in regular expressions), use Except["\n"], Except["\n"] .., and Except["\n"] .... In[12]:= StringCases["line1\nline2\n", __] Out[12]= {line1 line2 ] In[13]:= StringCases["line1\nline2\n", Except["\n"] ..] Out[13]= {line1, line2] In[14]:= StringCases["line1\nline2\n", RegularExpression[".+"]] Out[14]= {line1, line2] A list of patterns, such as {"a", "b", "c"], is equivalent to a list of alternatives, such as "a" "b" "c". This is convenient in that functions like Characters and CharacterRange can be used to specify classes of characters. In[15]:= StringReplace["the cat in the hat", x : Characters["aeiou"] x <> x] Out[15]= thee caat iin thee haat 4 Advanced String Patterns When Condition (/;) is used, the patterns involved are treated as strings as far as the rest of Mathematica is concerned, so you need to use ToExpression in some cases. In[16]:= StringCases["a13 a18 a41 a42", "a" ~~ x : DigitCharacter .. ~~ WordBoundary /; PrimeQ[ToExpression[x]] x] Out[16]= {13, 41] Similar to ordinary Mathematica patterns, the function in PatternTest (?) is applied to each individual character. In[17]:= StringCases["125378132", __ ?(ToExpression[] < 5 &)] Out[17]= {12, 3, 132] The Whitespace construct is equivalent to WhitespaceCharacter ... In[18]:= StringReplace["13 \t 17 \n22 19", Whitespace - ","] Out[18]= 13,17,22,19 You can insert a RegularExpression object into a general string pattern. In[19]:= StringCases["a13b12c17a32", "a" ~~ x : RegularExpression["\\d+"] x] Out[19]= {13, 32] This inserts a lookbehind constraint (see "Regular Expressions") to ensure that you only pick words preceded by "the ". In[20]:= StringCases["the cat in the hat", RegularExpression["(?<=the )"] ~~ WordCharacter ..] Out[20]= {cat, hat] StringExpression objects can be nested. In[21]:= StringCases["ba3a1a78a2b7ba9", "b" ~~ ("a" ~~ DigitCharacter) ..] Out[21]= {ba3a1a7, ba9] The Except construct for string patterns takes a single argument that should represent a single character or a class of single characters. This deletes all nonvowel characters from the string. In[22]:= StringReplace["the cat in the hat", Except[Characters["aeiou"]] - ""] Out[22]= eaiea When trying to match patterns of variable length (such as __ and patt ..), the longest possi- ble match is tried first by default. To force the matcher to try the shortest match first, you can wrap the relevant part of the pattern in Shortest[ ]. Advanced String Patterns 5 When trying to match patterns of variable length (such as __ and patt ..), the longest possi- ble match is tried first by default. To force the matcher to try the shortest match first, you can wrap the relevant part of the pattern in Shortest[ ]. In[23]:= StringCases["(ab) (cde)", "(" ~~ __ ~~ ")"] Out[23]= {(ab) (cde)] In[24]:= StringCases["(ab) (cde)", Shortest["(" ~~ __ ~~ ")"]] Out[24]= {(ab), (cde)] If for some reason you need a longest match within the short match, you can use Longest. In[25]:= StringCases["(ab132cd)137(ef576gh)", Shortest["(" ~~ ___ ~~ x : DigitCharacter .. ~~ ___ ~~ ")"] x] Out[25]= {1, 5] In[26]:= StringCases["(ab132cd)(ef576gh)", Shortest["(" ~~ ___ ~~ Longest[x : DigitCharacter ..] ~~ ___ ~~ ")"] x] Out[26]= {132, 576] You could alternatively rewrite this pattern without use of Longest. In[27]:= StringCases["(ab132cd)(ef576gh)", "(" ~~ Shortest[___] ~~ x : DigitCharacter .. ~~ Shortest[___] ~~ ")" x] Out[27]= {132, 576] Regular Expressions The regular expression syntax follows the underlying Perl Compatible Regular Expressions (PCRE) library, which is close to the syntax of Perl. (See [1] for further information and documen- tation.) A regular expression in Mathematica is denoted by the head RegularExpression. The following basic elements can be used in regular expression strings. 6 Advanced String Patterns c the literal character c . any character except newline [c 1 c 2 ] any of the characters c i [c 1 -c 2 ] any character in the range c 1 c 2
[^c 1 c 2 ] any character except the c i p- p repeated zero or more times p+ p repeated one or more times p? zero or one occurrence of p p{m,n] p repeated between m and n times p-?, p+?, p ?? the shortest consistent strings that match p-+, p++ , p?+ possessive match (p 1 p 2 ) strings matching the sequence p 1 , p 2 , p 1 |p 2 strings matching p 1 or p 2
The following represent classes of characters. \\d digit 09 \\D nondigit \\s space, newline, tab or other whitespace character \\S non-whitespace character \\w word character (letter, digit or _) \\W nonword character [[:class:]] characters in a named class [^[:class:]] characters not in a named class The following named classes can be used: alnum, alpha, ascii, blank, cntrl, digit, graph, lower, print, punct, space, upper, word, and xdigit. The following represent positions in strings. Advanced String Patterns 7 ^ the beginning of the string (or line) $ the end of the string (or line) \\A the beginning of the string \\z the end of the string \\Z the end of the string (allowing for a single newline charac - ter first) \\b word boundary \\B anywhere except a word boundary The following set options for all regular expression elements that follow them. (?i) treat uppercase and lowercase as equivalent (ignore case) (?m) make ^ and $ match start and end of lines (multiline mode) (?s) allow . to match newline (?x) disregard all whitespace and treat everything between "" and "\n" as comments (?-\#c) unset options The following are lookahead/lookbehind constructs. (?=p) the following text must match p (?!p) the following text cannot match p (?= p) the preceding text must match p (?!p) the preceding text cannot match p Discussion of a few issues regarding regular expressions follows. This looks for runs of word characters of length between 2 and 4. In[28]:= StringCases["a bb ccc dddd eeeee", RegularExpression["\\b\\w{2,4}\\b"]] Out[28]= {bb, ccc, dddd] 8 Advanced String Patterns With the possessive "+" quantifier, as many characters as possible are grabbed by the matcher, and no characters are given up, even if the rest of the patterns require it. In[29]:= StringCases["a2 b6", RegularExpression["\\w+\\d"]] Out[29]= {a2, b6] In[30]:= StringCases["a2 b6", RegularExpression["\\w++\\d"]] Out[30]= {] In[31]:= StringCases["a2 b6", RegularExpression["\\D++\\d"]] Out[31]= {a2, b6] [[ : xdigit :]] corresponds to characters in a hexadecimal number. In[32]:= StringCases["ff, 13, 1a3, xyz, 3b", RegularExpression["[[:xdigit:]]+"]] Out[32]= {ff, 13, 1a3, 3b] The complete list of characters that need to be escaped in a regular expression consists of ., \, ?, (, ), {, ], [, ], ^, $, -, +, and |. For instance, to write a literal period, use "\\." and to write a literal backslash, use "\\\\". Inside a character class "[]", the complete list of escaped characters is ^, -, \, [, and ]. By default, ^ and $ match the beginning and end of the string, respectively. In multiline mode, these match the beginning/end of lines instead. In[33]:= StringCases["line1\nline2", RegularExpression["^.+"]] Out[33]= {line1] In[34]:= StringCases["line1\nline2", RegularExpression["(?m)^.+"]] Out[34]= {line1, line2] In multiline mode, \\ A and \\ Z can be used to denote the beginning and end of the string. In[35]:= StringCases["line1\nline2", RegularExpression["(?m)\\A.+"]] Out[35]= {line1] Advanced String Patterns 9 The (? x) modifier allows you to add whitespace and comments to a regular expression for readability. In[36]:= StringCases["12.45 bc58.11", RegularExpression["\<(?x) \\d+ \\. remember to escape the period \\d+\>"]] Out[36]= {12.45, 58.11] Named subpatterns are achieved by surrounding them with parentheses (subpatt); they then become numbered subpatterns. The number of a given subpattern counts the opening parenthe- sis, starting from the start of the pattern. You can refer to these subpatterns using \\ n for the n th pattern later in the pattern, or by "$n" in the right-hand side of a rule. "$0" refers to all of the matched pattern. In[37]:= StringCases["a1b6a3b3a3c3a8b8", RegularExpression["(a(\\d))b\\2"]] Out[37]= {a3b3, a8b8] In[38]:= StringCases["a1b6a3b3a3c3a8b8", RegularExpression["(a(\\d))b\\2"] - {"$0", "$1", "Number:$2"}] Out[38]= {{a3b3, a3, Number:3], {a8b8, a8, Number:8]] If you need a literal $ in this context (when the head of the left-hand side is RegularExpression), you can escape it by using backslashes (for example, "\\$2"). In[39]:= StringCases["a1b6a3b3a3c3a8b8", RegularExpression["(a(\\d))b\\2"] - {"$0", "$1", "Number:$2", "Literal:\\$2"}] Out[39]= {{a3b3, a3, Number:3, Literal:$2], {a8b8, a8, Number:8, Literal:$2]] If you happen to need a single literal backslash followed by a literal $ under these circum- stances, you need to be a bit tricky and split into two strings temporarily. In[40]:= StringCases["a1b6a3b3a3c3a8b8", RegularExpression["(a(\\d))b\\2"] :> {"$0", "$1", "Number:$2", "Literal:\\" <> "\\$2"}] Out[40]= {{a3b3, a3, Number:3, Literal:\$2], {a8b8, a8, Number:8, Literal:\$2]] If you need to group a part of the pattern, but you do not want to count the group as a num- bered subpattern, you can use the (? :patt) construct. In[41]:= StringCases["a11b16c22b77", RegularExpression["(?:a|b)(\\d)\\1"]] Out[41]= {a11, b77] Lookahead and lookbehind patterns are used to ensure a pattern is matched without actually including that text as part of the match. 10 Advanced String Patterns This picks out words following the string "the ". In[42]:= StringCases["the cat in the hat", RegularExpression["(?<=the )\\w+"]] Out[42]= {cat, hat] This tries to pick out all even numbers in the string, but it will find matches that include partial numbers. In[43]:= StringCases["a23b42c63d80, 123", x : RegularExpression["\\d+"] /; Mod[ToExpression[x], 2] = 0] Out[43]= {2, 42, 6, 80, 12] Using lookbehind/lookahead, you can ensure that the characters before/after the match are not digits (note that the lookbehind test is superfluous in this particular case). In[44]:= StringCases["a23b42c63d80, 123", x : RegularExpression["(?<!\\d)\\d+(?!\\d)"] /; Mod[ToExpression[x], 2] = 0] Out[44]= {42, 80] RegularExpression versus StringExpression There is a close correspondence between the various pattern objects that can be used in general symbolic string patterns and in regular expressions. Here is a list of examples of patterns written as regular expressions and as symbolic string patterns. regular expression general string pattern explanation "abc" "abc" the literal string "abc" "." Except["\n"] any character except newline "(?s)." _ any character "(?s).+" __ one or more characters (greedy) "(?s).+?" Shortest[__] one or more characters (nongreedy) "(?s).-" ___ zero or more characters ".-" Except["\n"]... zero or more characters (except newlines) "a?b" "a" ""--"b" zero or one "a" followed by a "b" (that is, "b" or "ab") Advanced String Patterns 11 "[abef]" Characters[ "abef"] any of the characters "a", "b", "e", or "f" "[abef]+" Characters[ "abef"].. one or more of the characters "a", "b", "e", or "f" "[a-f]" CharacterRange[ "a","f"] any character in the range between "a" and "f" "[^abef]" Except Characters[ "abef"] any character except the characters "a", "b", "e", or "f" "ab|efg" "ab" "efg" match the strings "ab" or "efg" "(ab|ef)gh" or "(?:ab|ef)gh" ("ab" "ef")-- "gh" "ab" or "ef" followed by "gh" (that is, "abgh" or "efgh") "\\s" WhitespaceCh aracter any whitespace character "\\s+" Whitespace one or more characters of whitespace "(a|b)\\1" x:"a" "b"--x_ this will match either "aa" or "bb" "\\d" DigitCharacter any digit character "\\D" Except DigitCharacter
any nondigit character
"\\d+" DigitCharacter .. one or more digit characters "\\w" WordCharacter "_" any digit, letter, or "_" character "[[:alpha:]]" LetterCharact er any letter character "[^[:alpha:]]" Except LetterCharact er
SkilMaria and Elena are preparing for a party. Maria realizes she forgot to fill the ice cube trays in order to
have ice for the punch. Elena says that she remembers reading somewhere that hot water freezes faster than
cold water. Maria is skeptical. She learned in her physics class that the hotter the liquid, the faster the
molecules are moving. Since hot water molecules have to slow down more than cold water molecules to
become ice, Maria thinks that it will take hot water longer to freeze than cold water.
The girls decide to conduct a scientific experiment to determine whether it is faster to make ice cubes with
hot water or cold water.l and Practice