51Testing软件测试论坛

标题: 讨教一个关于“正则表达式”的问题 [打印本页]

作者: angel_test    时间: 2006-11-24 11:29
标题: 讨教一个关于“正则表达式”的问题
1、正则表达式的作用?
2、比如:在用户手册中,可以在属性值和检查点中使用。但是在属性值中,比如一个录制过程:提交一个表单操作,输入数据,点击“提交”按钮,如表单数据不完整,返回表单给用户,用户输入完整的数据,点击“重新提交”按钮,把这个按钮的“名字”属性修改为正则表达式。
      这个过程我都录制下来了,有必要把属性改为正则表达式吗?
作者: yangkinki    时间: 2006-11-24 11:48
In a typical search and replace operation, you must provide the exact text you are looking for. That technique may be adequate for simple search and replace tasks in static text, but it lacks flexibility and makes searching dynamic text difficult, if not impossible.

With regular expressions, you can:

Test for a pattern within a string. For example, you can test an input string to see if a telephone number pattern or a credit card number pattern occurs within the string. This is called data validation.
Replace text. You can use a regular expression to identify specific text in a document and either remove it completely or replace it with other text.
Extract a substring from a string based upon a pattern match. You can find specific text within a document or input field
For example, if you need to search an entire web site to remove some outdated material and replace some HTML formatting tags, you can use a regular expression to test each file to see if the material or the HTML formatting tags you are looking for exists in that file. That way, you can narrow down the affected files to only those that contain the material that has to be removed or changed. You can then use a regular expression to remove the outdated material, and finally, you can use regular expressions to search for and replace the tags that need replacing.

Another example of where a regular expression is useful occurs in a language that isn't known for its string-handling ability. VBScript, a subset of Visual Basic, has a rich set of string-handling functions. JScript, like C, does not. Regular expressions provide a significant improvement in string-handling for JScript. However, regular expressions may also be more efficient to use in VBScript as well, allowing you do perform multiple string manipulations in a single expression.
具体请看帮助文档




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2