如何使用正则表达式在ActionScript3中搜索XML文件中的属性?

tme*_*iaa 0 xml actionscript-3

我有一个像这样的xml文件:

<data>
<season id="00">
    <project id="text"/>
    <project id="test"/>
    <project id="move"/>
    <project id="moser"/>
    <project id="moment"/>
    <project id="save"/>
    <project id="safe"/>
    <project id="search"/>      
</season>
<season id="01">
    <project id="send"/>
    <project id="serve"/>
    <project id="service"/>
    <project id="mondey"/>
    <project id="mother"/>
    <project id="tesla"/>
    <project id="tiser"/>
    <project id="spacnk"/>      
</season>
Run Code Online (Sandbox Code Playgroud)

我想找到带有regexp的xmllist来匹配属性中的一些文本,例如"se"或"mo".请帮我.

Dec*_*ler 5

var xml:XML = 
<data>
    <season id="00">
        <project id="text"/>
        <project id="test"/>
        <project id="move"/>
        <project id="moser"/>
        <project id="moment"/>
        <project id="save"/>
        <project id="safe"/>
        <project id="search"/>
    </season>
    <season id="01">
        <project id="send"/>
        <project id="serve"/>
        <project id="service"/>
        <project id="mondey"/>
        <project id="mother"/>
        <project id="tesla"/>
        <project id="tiser"/>
        <project id="spacmonk"/>
    </season>
</data>;

trace( xml..project.( @id.match( /se/ ) ).toXMLString() );
Run Code Online (Sandbox Code Playgroud)

说明:

xml     // using the XML data in our xml variable
..      // find descendants at any level
project // that is an element of type project
(       // open an expression to evaluate
@id     // using attribute 'id' of our project elements
.match( // find matching 'id' values using regular expression
/se/    // find the string 'se' anywhere in the string that is evaluated
)       // close match()
)       // close expression
Run Code Online (Sandbox Code Playgroud)

要仅匹配具有以"se"开头的id属性的项目元素,您只需像往常一样更改正则表达式:

/^se/
Run Code Online (Sandbox Code Playgroud)

以"se"结尾:

/se$/
Run Code Online (Sandbox Code Playgroud)

...等