看来正则需要好好学习学习了,今天遇到了个截取字符串的问题。
有个字符串,格式如下:
var vcard='<vCard xmlns="vcard-temp"><N><GIVEN>1</GIVEN></N><BDAY>2</BDAY><EMAIL>3</EMAIL><URL>4</URL><ADR><CTRY>5</CTRY><REGION>6</REGION><LOCALITY>7</LOCALITY><STREET>8</STREET><EXTADD>9</EXTADD><PCODE>10</PCODE></ADR><ORG><ORGNAME>11</ORGNAME><ORGUNIT>xxxxxxxxxxxxx</ORGUNIT></ORG><TITLE>12</TITLE><ROLE>13</ROLE><DESC>14</DESC></vCard>';
所需<ORGUNIT>xxxxxxxxxxxxx</ORGUNIT>中的值
解决方法如下:
var vcard='<vCard xmlns="vcard-temp"><N><GIVEN>1</GIVEN></N><BDAY>2</BDAY><EMAIL>3</EMAIL><URL>4</URL><ADR><CTRY>5</CTRY><REGION>6</REGION><LOCALITY>7</LOCALITY><STREET>8</STREET><EXTADD>9</EXTADD><PCODE>10</PCODE></ADR><ORG><ORGNAME>11</ORGNAME><ORGUNIT>xxxxxxxxxxxxx</ORGUNIT></ORG><TITLE>12</TITLE><ROLE>13</ROLE><DESC>14</DESC></vCard>'; var t,reg = /<ORGUNIT>([\s\S]*?)<\/ORGUNIT>/ig; while((t=reg.exec(vcard))!=null){ alert(t[1]); }
dml@2013.1.7
作者:duanml61 发表于2013-1-7 11:42:20 原文链接
阅读:33 评论:0 查看评论