מדריך מקוצר בהחלט לשימוש ב-Regular Expressions
כדי להשתמש ב-Regular Expressions צריך לזכור את החוקיות הבאה:
נקודה (.) מייצגת תו כלשהו.
. = One single char
פלוס (+) מייצג חזרה של 1 או יותר פעמים.
.+ = Single char or more
סימן שאלה (?) מייצג חזרה של 0 או 1 פעמים.
.? = Single char or no char at all
כוכבית (*) מייצגת חזרה של 0 או יותר פעמים.
.* = Everything
ניתן להשתמש במקף (-) כדי ליצור טווח של תווים להתאמה. דוגמה לכזה טווח של תווים אלפאנומרים:
[A-Za-z0-9]
"כובע" (^) מייצג התחלה של מחרוזת.
דולר ($) מייצג סוף של מחרזות.
תווי Escape:
s = space, n = new line, r = CR char (good for DOS new line), \ = , ( = (.
קישורים שימושיים:
http://www.regular-expressions.info/reference.html
http://www.orafaq.com/node/2404
expression-ים שימושיים (דוגמאות דרך פקודות של אורקל):
וידוא כי כתובת דואל תקינה:
SQL> select case
  2             when REGEXP_LIKE('moyshe.zichmich@gmail.com',
  3                              '^([[:alnum:]]+(_?|.))[[:alnum:]]*@[[:alnum:]]+(.([[:alnum:]]+)){1,2}$') then
  4              'email okay'
  5             else
  6              'not email'
  7         end as output
  8    from dual;
 
OUTPUT
----------
email okay
חילוץ כתובת אתר אינטרנט מתוך מחרוזת:
SQL> SELECT REGEXP_SUBSTR('http://www.oracle.com/pls/db102/search?remark=quick_search&format=ranked&word=select',
  2                       'http(s?)://([[:alnum:]]+.?){3,4}/?') RESULT
  3    FROM dual;
 
RESULT
----------------------
http://www.oracle.com/

השאירו תגובה
Want to join the discussion?Feel free to contribute!