среда, 30 октября 2013 г.

Регулярные выражения

Исключаем не цифровые значения:

 DATALS_RANGE  TYPE RSSDLRANGE,
        L_IDX LIKE SY-TABIX.


  BREAK-POINT.
*  READ TABLE L_T_RANGE WITH KEY
*       FIELDNAME = 'COMP_CODE'.
*  L_IDX = SY-TABIX.

  SELECT COMP_CODE
    FROM /BI0/MCOMP_CODE
    INTO LS_RANGE-LOW
    WHERE COMP_CODE NE '0800'
      AND COMP_CODE NOT BETWEEN '0803' AND '0899'
      AND OBJVERS EQ 'A'.

    LS_RANGE-SIGN 'I'.
    LS_RANGE-OPTION  'EQ'.
    LS_RANGE-FIELDNAME 'COMP_CODE'.

    DATA TYPE STRING.
    S LS_RANGE-LOW.
    FIND REGEX '\d\d\d\d' IN S.
    IF SY-SUBRC EQ 0.
      APPEND LS_RANGE TO L_T_RANGE.
    ELSE.
      CLEAR LS_RANGE.
    ENDIF.

  ENDSELECT.

  DELETE L_T_RANGE
    WHERE FIELDNAME EQ 'COMP_CODE'
      AND LOW EQ 0.

*  MODIFY L_T_RANGE INDEX L_IDX.

  P_SUBRC 0.



Patterns Syntax 

Use

Bounced Mail Framework (BMF) patterns are Java regular expressions (Java RegEx).
To create or understand a pattern, you need to know the syntax of Java regular expressions.
The basics of creating simple patterns are described here.
Link to external website
You can find more information about Java regular expressions athttp://java.sun.com/docs/books/tutorial/essential/regex/.

Basic Regular Expression Constructors

Characters
Syntax
Description
x
Character x
\\
Backslash (\)
\t
Tab
\n
New line
\.
Period (.)
Character Classes
Syntax
Description
[abc]
a, b, or c (simple class)
[^abc]
Any character except a, b, or c (negation)
[a-zA-Z]
a through z, or A through Z, inclusive (range)
Example
The pattern[chw]all matches the words callhall and wall.
This pattern does not match any other words (for example, ball) and it does not match words in uppercase (CallWall and Hall). To match both uppercase and lowercase words, use the pattern [cChHwW]all.
Predefined Character Classes
Syntax
Description
.
Any character
\d
A digit (0-9)
\D
A nondigit – all characters except (0-9)
\s
A white space (for example, space, tab, new line)
\S
A nonwhite space – all characters except white spaces
\w
A word character – all characters from a-z, A-Z, all digits and underscore (_)
\W
A nonword character – all characters except word characters
Example
The pattern \w\w\w\ matches three word characters, for example abcSAPA1b999 and 5r_.
It does not match abcd (length different than 3) or a c (due to white space).
Greedy Quantifiers
Syntax
Description
X?
X, once or no times
X*
X, zero or more times
X+
X, one or more times
X{n}
X, exactly n times
X{n,}
X, at least n times
X{n,m}
X, at least n but not more than m times
Note
To use greedy quantifiers, you must replace X with any character or character class.
Example
The pattern \w\w\w\ is equivalent to the pattern \w{3}.

Composite Patterns

You can write several patterns on one line if you separate them with spaces.
In this case, to match the composite patterns, each sub pattern must match.
Example
The composite pattern \w+ \d+ matches 123 but does not match abc.
The composite pattern \w+ \W+ does not match anything.

Example

In this example, you create a pattern for matching mail addresses.
  1.  Look at the following pattern:
(\w+)@
The w+ indicates that one or more word characters must appear. This must be followed by an at sign (@).
The parentheses () are not required here, but they divide the expression into groups and this can be useful when you need to change a logical part of the pattern.
Example
This pattern matches the following examples:
mona@
hansbosch@
Jose_Rodriguez@
  2.  Extend the pattern to the following:
(\w+)@(\w+\.)(\w+)
The (\w+\.) group is similar, but expects a period (.) to follow.
The period is escaped using a backslash (\) because the period character itself matches any character.
The (\w+) group is already explained in the previous step.
Example
This pattern matches the following examples:
mona@yourcompany.org
hansbosch@company.com
Jose_Rodriguez@isp.net
  3.  Extend the pattern to the following:
(\w+)@(\w+\.)(\w+)(\.\w+)*
The (\.\w+) group matches a period (.) followed by one or more word characters.
The asterisk (*) denotes that the preceding character or group can occur zero or more times.
Since the parentheses () denote a group and the asterisk (*) applies to the whole group, the pattern matches a period (.) followed by one or more word characters, and it matches that combination zero or more times.
Example
This pattern matches the following examples:
mona@office1.yourcompany.org
hansbosch@management.company.com
Jose_Rodriguez@server5.region3.my.isp.net
It still does not match periods before the at sign (@), for example:
nina.smith@sap.com
  4.  Use this pattern to match any e-mail address:
(\w+)(\.\w+)*@(\w+\.)(\w+)(\.\w+)*
You can easily change this pattern to include the addresses you need.
For example, if you need to match all e-mail addresses from the domain company.com, change the pattern to:

(\w+)(\.\w+)*@company\.com

Комментариев нет:

Отправить комментарий