[英]Javascript jQuery: regexp on fieldset
I got a problem with a regexp in javascript so i'm requesting for your help. 我在javascript中遇到了一个正则表达式问题,因此我需要您的帮助。
So, I got an ajax query result stored in a var (regexp in this case) and I want to match only the content of the fieldset tag. 因此,我将ajax查询结果存储在var(在本例中为regexp)中,我只想匹配fieldset标记的内容。
Here's part of my HTML: 这是我的HTML的一部分:
<fieldset class="form-wrapper" >
<form action="/users/login" id="UserLoginForm" method="post" accept-charset="utf-8"><div style="display:none;">
<input type="hidden" name="_method" value="POST" /></div>
<div class="input text required">
<label for="UserUsername">Username</label>
<input name="data[User][username]" type="text" maxlength="255" id="UserUsername" />
</div>
<div class="input password">
<label for="UserPassword">Password</label>
<input type="password" name="data[User][password]" id="UserPassword" />
</div>
<div class="submit">
<input type="submit" value="Login" />
</div>
</form>
<p id="user-management-links">
<a href="/users/forgotten_password">Forgotten password ?</a>
| <a href="/users/register">Sign up</a>
</p>
</fieldset>
And here's my regexps : 这是我的正则表达式:
This one work : var regexp = content.match(/<form .*?>(.*?)<\\/form>/)[0];
这项工作:
var regexp = content.match(/<form .*?>(.*?)<\\/form>/)[0];
This one not : var regexed = content.match(/<fieldset>(.*)<\\/fieldset>/)[0];
这个不是:
var regexed = content.match(/<fieldset>(.*)<\\/fieldset>/)[0];
Thanks for your answers! 感谢您的回答!
var regexed = content.match(/<fieldset .*?>(.*)<\/fieldset>/)[0];
You forgot the .*? 您忘记了。*? from the first one, i think.
我认为从第一个开始。
EDIT: that would work if javascript would have the option to enable the dot to match also spaces and new lines (reason why probably it is not working for you) 编辑:如果javascript可以选择启用点以匹配空格和换行符,这将起作用(原因为何可能对您不起作用)
I came up with this: 我想出了这个:
<fieldset .*? >(.|\W)*</fieldset>
that works without any options enabled 无需启用任何选项即可工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.