Choosing The Right Server-Side Scripting Language
By Craig McElwee2004-01-06
Task 3: Search and Replace
Perl has the most powerful regular expression engine and excels at text manipulation. If your next program requires much text manipulation, you'll be hard pressed to find a reason not to use Perl. That said, Python, PHP, and Tcl support regular expression searching and replacing, though the interface in each appears awkward and convoluted when compared to Perl's elegant syntax. Here are examples from the scripts, modified so each uses the same simple variable name for clarity. In each example, a case-insensitive search for the sequence of letters "cat" is made in the value of the variable 'data', and for each successful find, those letters are replaced with the sequence "dog":
Perl:
|
PHP:
|
Python:
|
Tcl:
|
The Java language lacks integrated regular expressions, but this is a rather simple substitution that we can manage with substrings:
Java:
|
This is extremely inelegant. We could have worked similar solutions in the other languages, but a clear, concise, single statement seems far superior. For whatever reason, Sun decided to leave regular expressions out of the standard Java distribution.
Tutorial pages:
|
First published by IBM developerWorks
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "Choosing The Right Server-Side Scripting Language"
You must be logged in to post a comment.
Link to This Tutorial Page!

