开发者

Help with Regex on Parameter delimiter

开发者 https://www.devze.com 2023-01-30 18:51 出处:网络
I have to match the following text: var html = \'<td align=\"right\" width=\"26%\"> <span class=\"text2-mbna\" style=\"position:relative; left:10px;\">

I have to match the following text:

var html = '<td align="right" width="26%">


            <span class="text2-mbna" style="position:relative; left:10px;"> 
            $0.开发者_运维问答00</span>

    </td>'

I have this regex

/<span class="text2-mbna" style="position:relative; left:10px;">(?:\s+)((?:\$)((\d|,)+)\.(\d+))<\/span>/.exec(html)

I can actually just replace it in javascript, but I want to know how to NOT capture the dollar($) sign.


Just move (?:\$) before the open paren to its left, giving:

/<span class="text2-mbna" style="position:relative; left:10px;">(?:\s+)(?:\$)(((\d|,)+)\.(\d+))<\/span>/

You don't need (?:) there anyway; it can just be

/<span class="text2-mbna" style="position:relative; left:10px;">\s+\$(((\d|,)+)\.(\d+))<\/span>/
0

精彩评论

暂无评论...
验证码 换一张
取 消