我的字符串:
<div class="sect1" id="s9781473910270.i101">
<div class="sect2" id="s9781473910270.i102">
<h1 class="title">1.2 Summations and Products[label*summation]</h1>
<p>text</p>
</div>
</div>
<div class="sect1" id="s9781473910270.i103">
<p>sometext [ref*summation]</p>
</div>
<div class="figure" id="s9781473910270.i220">
<div class="metadata" id="s9781473910270.i221">
</div>
<p>fig1.2 [label*somefigure]</p>
<p>sometext [ref*somefigure]</p>
</div>
Run Code Online (Sandbox Code Playgroud)
目标: 1.在上面的字符串中label*string,ref*string是交叉引用.取而代之的是[ref*string]我需要用and a的属性替换,href是相关位置的id .和班级是classhrefdivlabel*adiv
a元素类和ID是它们的相对div类名和ID.但如果div class="metadata"存在,需要忽略它不应该采取他们的类名和ID.预期产量:
<div class="sect1" id="s9781473910270.i101">
<div class="sect2" id="s9781473910270.i102">
<h1 class="title">1.2 Summations and Products[label*summation]</h1>
<p>text</p>
</div>
</div>
<div class="sect1" id="s9781473910270.i103">
<p>sometext <a class="section-ref" href="s9781473910270.i102">1.2</a></p> …Run Code Online (Sandbox Code Playgroud) 我想捕获匹配的花括号。
例如:
Some example text with \added[author]{text with curly braces{some text}..}
Some example text with \added[author]{text without curly braces}
Some example text with \added[author]{text with {}and {} and {}curly braces{some text}..}
Some example text with \added[author]{text with {}and {} and {}curly braces{some text}..} and extented text with curly braces {}
预期输出:
Some example text with text with curly braces{some text}..
Some example text with text without curly braces
Some example text with text with {}and {} and {}curly braces{some …
我需要获取子匹配字符串的索引位置值。根据文档,我已经阅读了此正则表达式并了解了FirstIndex属性以获取匹配字符串的位置。
但这仅适用于一维匹配的字符串。我无法申请子FirstIndex比赛。请参考样本匹配
我尝试过这种格式,
Dim myRegExp As Object, match As MatchCollection
Dim matched As String
Set myRegExp = CreateObject("VBScript.RegExp")
myRegExp.pattern = find
If myRegExp.test(text) = True Then
Set match = myRegExp.Execute(text)
Debug.Print match(0).submatches(0) '' this is matched string
Run Code Online (Sandbox Code Playgroud)
我应该在哪里打电话FirstIndex以获得匹配的字符串的位置
输出:
match(0)=>Berry, Brent. (2006). What accounts for race and ethnic differences in Berry,
Brent. parental financial transfers to adult children in the United States? Journal of Family
Issues 37:1583-1604.
submatches(0)=>Berry, Brent.
submatches(6)=>2006
Run Code Online (Sandbox Code Playgroud)
预期的输出: …