<custom type=x,name=y,age=z> the custom object. </custom>
有两种需求:
1.取得 xml 的这一部分:
type=x,name=y,age=z
2.取得 the custom object 这一部分。
请问一下这个正则表达式该怎么写呢?
<custom type=x,name=y,age=z> the custom object. </custom>
有两种需求:
1.取得 xml 的这一部分:
type=x,name=y,age=z
2.取得 the custom object 这一部分。
请问一下这个正则表达式该怎么写呢?
楼主要什么语言的解决方案?用Ruby的话可以这样:
[code="ruby"]/(.*?)<\/custom>/m[/code]
用的话类似:
[code="irb"]str = <
the custom object.
STR
r = /(.*?)<\/custom>/m
str =~ r
$1 # "type=x,name=y,age=z"
$2 # "\nthe custom object.\n"[/code]
另外楼主确定要匹配的文本是
[code="xml"]
the custom object.
[/code]
而不是
[code="xml"]
the custom object.
[/code]
么?