Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ABAP regular expressions to parse HTML tags

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use ABAP regular expressions to parse HTML tags. I hope you will get something after reading this article. Let's discuss it together.

The requirement is that I use a function of ABAP to read a string from the database, and the content of the string is a web page.

The form of the web page contains a lot of hidden input field. My task is to parse the value of input field whose name is svyValueGuid: FA163EEF573D1ED89E89C7FE5E7C4715

The simplest and most rude way is to use the FIND FIRST OCCURRENCE keyword of ABAP to first find the offset of svyValueGuid, then start from this offset, and then find the offset of the first >, so that the problem is reduced to type= "hidden" value= "FA163EEF573D1ED89E89C7FE5E7C4715" in the substring, which makes the problem much easier. But this approach is cumbersome and the code is redundant.

Is there a faster way? That is to use ABAP regular expression, or regular expressions.

Look at the following test code:

REPORT ztest_interface.DATA: lv_input TYPE string Reg_pattern TYPE string.lv_input = ``& & `reg _ pattern ='. * svyValueGuid (?:. *) value= "(. *)" >. * SurveyId.*'.TRY.DATA (lo_regex) = NEW cl_abap_regex (pattern = reg_pattern) .Data (lo_matcher) = lo_regex- > create_matcher (EXPORTING text = lv_input). IF lo_matcher- > match ( ) abap_true.WRITE:/ 'fail in input scanned INDEX 1.data. RETURN.ENDIF.data (lt_reg_match_result) = lo_matcher- > find_all (). READ TABLE lt_reg_match_result ASSIGNING FIELD-SYMBOL () INDEX 1.READ TABLE-submatches ASSIGNING FIELD-SYMBOL () INDEX 1.data (lv_sub) = lv_input+-offset (- length). WRITE:/' result:' Lv_sub.CATCH cx_root INTO DATA (cx_root). WRITE:/ cx_root- > get_text (). RETURN.ENDTRY.

Execution result:

The core idea of solving the problem is this regular expression: .svyValueGuid (?:.) value= "(.)" >. SurveyId.***

The 32-bit guid value is captured by capturing the grouping operator and a pair of parentheses. This solution has less code than FIND FIRST OCCURANCE.

After reading this article, I believe you have some understanding of "how to use ABAP regular expressions to parse HTML tags". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report