ebook img

Regular Expressions for Information Processing in ABAP PDF

32 Pages·2006·0.58 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Regular Expressions for Information Processing in ABAP

Regular Expressions for Information Processing in ABAP Ralph Benzinger SAP AG Regular Expression Primer Using Regular Expressions in ABAP Working with Regular Expressions Ubiquitous Text Processing (1) Checking input for validity: Does credit card number contain only digits, hyphens, and spaces? METHODS check IMPORTING cardno TYPE c RETURNING result TYPE abap_bool. "… 1234 5678 1234 5678 1234 5678 1234 XXXX 1234-5678-1234-5678 © SAP AG2006, S3 Vortrag/ 21.2.2006 / 3 Ubiquitous Text Processing (2) Extracting information from text: What is the document ID requested by the web client? METHODS retrieve IMPORTING url TYPE c RETURNING doc TYPE xstring. "… http://sap.com/&user=ralph&id=1234&lang=EN © SAP AG2006, S3 Vortrag/ 21.2.2006 / 4 Ubiquitous Text Processing (3) Normalizing values: Eliminate non-digits in phone number for data export METHODS export IMPORTING phoneno TYPE c RETURNING digits TYPE n. "… +49 (6227) 7-47474 496227747474 © SAP AG2006, S3 Vortrag/ 21.2.2006 / 5 Sample Text Processing Problem Remove all HTML tags from a given block of text <h2 id="slogan">Leading the Web to Its Full Potential...</h2> <p class="small">The World Wide Web Consortium (<acronym>W3C</acronym>) develops interoperable < > technologies to lead the Web to its full potential. W3C is a forum for information, commerce, Leading the Web to Its Full Potential... The communication, and collective understanding. On this page, you'll find <a href="#news">W3C news</a>, World Wide Web Consortium (W3C) develops interoperable links to <a href="#technologies">W3C technologies to lead the Web to its full potential. W3C is a technologies</a> and ways to <a href="#contents">get involved</a>. New visitors can find help in <cite><a forum for information, commerce, communication, and href="/2002/03/new-to-w3c">Finding Your Way at collective understanding. On this page, you'll find W3C W3C</a></cite>. We encourage you to read the <cite><a href="/Consortium/Prospectus/">Prospectus news, links to W3C technologies and ways to get involved. </a></cite> and learn <a href="/Consortium/">more New visitors can find help in Finding Your Way at W3C. about W3C</a>.</p>' We encourage you to read the Prospectus and learn more about W3C. © SAP AG2006, S3 Vortrag/ 21.2.2006 / 6 “Patterns? Been there, done that!” Traditional ABAP offers some trivial patterns for text processing * one or more characters + any single character (cid:132) For use with CP operator (cid:132) Also used by F4 help Sorry, but CP less useful than it seems (cid:132) Cx abbreviates “contains x”, but ... (cid:132) CP abbreviates “covers pattern” – does not search inside of text WHILE text CP '<*>'. " loop hardly ever entered ENDWHILE. (cid:132) Pattern “ *<*>* ” won't tell us position of closing bracket © SAP AG2006, S3 Vortrag/ 21.2.2006 / 7 Improving Information Processing with REs Regular Expressions (REs, regexes) provide powerful pattern language for text processing (cid:132) Well understood Developed by mathematician Kleene in the 1950s (cid:139) (cid:132) Powerful Highly focused special purpose language (cid:139) Many common text processing tasks turn into (cid:139) simple one-liners (cid:132) Standardized and widely used Made popular by Unix tools: grep, sed, awk, emacs (cid:139) Stephen C. Kleene Built into some languages like Perl and Java; (cid:139) Image ©U. of Wisconsin add-on libraries available for many others Early Unix de-facto standard formalized in PCRE and POSIX (cid:139) As of Release 7.00, ABAP supports POSIX-style regular expressions © SAP AG2006, S3 Vortrag/ 21.2.2006 / 8 Regular Expression Basics Regular expressions are patterns built from (cid:132) Literals (characters) (cid:132) Operators (meta characters) . * + ? | ^ $ ( ) [ ] { } \ (cid:132) Prepending " \ " turns operators into literals Basic regex terminology (cid:132) An RE represents a set of literal text strings (cid:132) RE matches text if complete text is represented by RE Covers (cid:132) REs are commonly used for searching text (cid:132) Text to be searched may contain one or more matches Contains © SAP AG2006, S3 Vortrag/ 21.2.2006 / 9 Tool Support: Regex Toy DEMO_REGEX_TOY © SAP AG2006, S3 Vortrag/ 21.2.2006 / 10

Description:
Improving Information Processing with REs Regular Expressions (REs, regexes) provide powerful pattern language for text processing
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.