The understanding of regexp parameter-inline of TCL regular expression command

Source: Internet
Author: User
Tags regular expression snmp

Tcl "seems" to have a new parameter-inline for the regular expression command regexp after the 8.4 version:

-inline Causes the command to return, as a list, the data that would otherwise is placed in match variables. When using the -inline, match variables May is not specified. If used with -all, the list would be concatenated at each iteration, and such that a flat list are always returned. For each match iteration, the command would append the overall match data, plus one element for each subexpression in the R Egular expression. Examples is:

regexp -inline--{\w (\w)} "inlined"
      →in n
regexp -all-inline--{\w (\w)} "inlined"
      → In n li I ne E

The return value that is understood to be an expression is no longer 1 (success) or 0 (failed).

Instead of a list, the value of this list is all the content matched by the pattern of the regular expression + the contents of each sub-pattern match (each sub-pattern match result is an element of list);

If the-all parameter is added, the returned list is the content of the result connection (Contat) that all iterations match.


In fact, if-all is not added, it is equivalent to:

RegExp--{\w (\w)} "inlined" Match sub1

Where match is the content of all matches, and Sub1 is the sub-mode content.


The experiment encountered a problem (in fact, it doesn't matter with-inline):

% Set tokenlist_02 {vsb_components_t1 = "Feature_ipnet_inet6 2 feature_snmp_v3 y component_tunnel_support y SNMP[0-9_]+ 1 Feature_snmp_agentx y "}


% Set Token_items [regexp-inline {([^\s\=\]]+) \s*=\s* (. *)} $tokenList _02]

% lindex $token _items 0
VSB_COMPONENTS_T1 = "Feature_ipnet_inet6 2 feature_snmp_v3 y component_tunnel_support y SNMP[0-9_]+ 1 FEATURE_SNMP_ Agentx y "

% lindex $token _items 1
Vsb_components_t1

% lindex $token _items 2
"Feature_ipnet_inet6 2 feature_snmp_v3 y component_tunnel_support y snmp[0-9_]+ 1 feature_snmp_agentx y"

% llength [lindex $token _items 2]
1-------------------------------------------------> How could it be 1, shouldn't it be 10?


In fact, you don't see the double quotes, and the quotation marks make all of the contents an element of the list.

% llength [lindex [lindex $token _items 2] 0]
10


That's the result.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.