String Modifiers 

String Modifiers
  • Finally, pattern matching can be used to modify strings of text. One of the most common methods of modification is substitution. Substitution is performed using the format 
  • s/[pattern_to_find]/[pattern_to_replace_with]/
  • Thus, for example, the line: 
  • s/eric/selena/ 
  • would change the line 
  • eric is my name 
    to 
    selena is my name 
  • The substitution function is modified most commonly with the /i and the /g arguments. The /i argument specifies that matching should be done with case insensitivity and the /g specifies that the match should occur globally for the entire string of text rather than just for the first occurrence. 
  • Thus, the line 
  • s/eric/selena/gi 
    would change the line: 
    I am Eric, eric I am 
    to 
    I am selena, selena I am 
  • without the /i, you would get 
  • I am Eric, selena I am 
  • and without /g but with the /i, you would get 
  • I am selena, eric I am 
  • There are many, many different kinds of matching operators, anchors, and string modifiers. If you want a more detailed explanation I recommend that you find a good reference source on Regular Expressions. Otherwise, the above discussion should explain how operators and anchors are commonly used in CGI applications. 

Additional Resources:

Anchors
Table of Contents
The =~ operator


Graphics & Media Lab. >> Библиотека | Курсы | Графикон

Hosted by Graphics & Media Lab
http://graphics.cs.msu.su
lab_logo
mailto: Laboratory