特殊表示式 :
1.貨幣格式: '123123211312.333333'.replace(/(?=(?!^)(?:\d)+(?:\.|$))(\d(\.\d+$)?)/g, ',$1') //輸出 123,123,211,312.333333 ps:tcl 大牛推薦
另外,replace也支援regex關鍵字。
最後:只能是ecc6或者更高版本才可以(abap supports posix regular expressions as of release 7.00)
report z_test.
data: str type string ,
result_tab type match_result_tab ,
wa like line of result_tab.
*找出string裡面的雙位元組字元
str = 'abc我啊adfsf們'.
find all occurrences of regex '[^x00-xff]*' in str results result_tab.
loop at result_tab into wa.
write / str+wa-offset(wa-length).
endloop.
*找出string裡面的單位元組字元
str = 'abc我啊adfsf們'.
find all occurrences of regex '[x00-xff]*' in str results result_tab.
write / '-----'.
loop at result_tab into wa.
write / str+wa-offset(wa-length).
endloop.
*找出string裡面的ip位址
str = 'ip1:172.16.32.12 ip2:192.168.1.1 '.
find all occurrences of regex 'd+.d+.d+.d+' in str results result_tab.
write / '-----'.
loop at result_tab into wa.
write / str+wa-offset(wa-length).
endloop.
*找出string裡面的***-********格式的**號碼
str = 'ip1:172.16.32.12 021-12345678 '.
find all occurrences of regex 'd-d|d-d' in str results result_tab.
write / '-----'.
loop at result_tab into wa.
write / str+wa-offset(wa-length).
endloop.
*找出string裡面的15/18位身份證號碼
str = 'ip1:172.16.32.12 3722198003041234 '.
find all occurrences of regex 'd|d' in str results result_tab.
write / '-----'.
loop at result_tab into wa.
write / str+wa-offset(wa-length).
endloop.
***使用class的例子:
report z_barry_test.
parameters: p_input type string default 'ip1:172.16.32.12 ip2:192.168.1.1 ' obligatory.
data: regex type ref to cl_abap_regex,
matcher type ref to cl_abap_matcher,
match type c .
data: result_tab type match_result_tab ,
wa like line of result_tab.
create object regex
exporting
pattern = 'd+.d+.d+.d+'
ignore_case = 'x'.
try.
call method regex->create_matcher
exporting
text = p_input
* table =
receiving
matcher = matcher .
catch cx_sy_matcher .
endtry.
try.
call method matcher->match "是否完全匹配
receiving
success = match.
catch cx_sy_matcher .
endtry.
call method matcher->find_all
receiving
matches = result_tab.
loop at result_tab into wa.
write / p_input+wa-offset(wa-length).
endloop.
***sap給的判斷email位址的例子***
parameters email type c length 30 lower case default
ABAP系列 SAP ABAP常用正規表示式大全
sap technical matinal 原文出處 abap系列 sap abap常用正規表示式大全 特殊表示式 1.貨幣格式 123123211312.333333 replace d d d g,1 輸出 123,123,211,312.333333 ps tcl 大牛推薦 另外,replac...
ABAP系列 SAP ABAP常用正規表示式大全
sap technical matinal 原文出處 abap系列 sap abap常用正規表示式大全 特殊表示式 1.貨幣格式 123123211312.333333 replace d d d g,1 輸出 123,123,211,312.333333 ps tcl 大牛推薦 另外,replac...
正規表示式 常用正規表示式
一 校驗數字的表示式 1 數字 0 9 2 n位的數字 d 3 至少n位的數字 d 4 m n位的數字 d 5 零和非零開頭的數字 0 1 9 0 9 6 非零開頭的最多帶兩位小數的數字 1 9 0 9 0 9 7 帶1 2位小數的正數或負數 d d 8 正數 負數 和小數 d d 9 有兩位小數的...