Jsoup getElementsByAttributeValueMatching(Jsoup getElementsByAttributeValueMatching)
[JSoup讨论页面建议我在这里问我的问题。]
所以,我不是正则表达式专家,但我想知道我从jsoup getElementsByAttributeValueMatching()方法得到的结果。
如果我有一个html页面,其中包含(以及其他)以下链接:
<a href="/tweb/tiles/twr/EIDS_AT_20130108T134335/01/">Parent Directory</a> <a href="1357681618315/">1357681618315/</a> <a href="1357681649996/">1357681649996/</a>
我查询:
Elements dirs = baseDir.getElementsByAttributeValueMatching("href", Pattern.compile("[0-9]+/"));
希望只获得只有数字的2个链接(以及最后的斜杠)。
但是,我得到了所有3个链接。
我编写了一个快速测试程序,用3 href字符串检查java的Pattern Matcher对该正则表达式的响应,并且它只返回两个只有我期望的数字:
String a = "/tweb/tiles/twr/EIDS_AT_20130108T134335/01/"; String b = "1357681618315/"; String c = "1357681649996/"; Pattern p = Pattern.compile("[0-9]+/"); System.out.println("a:"+ p.matcher(a).matches()); System.out.println("b:"+ p.matcher(b).matches()); System.out.println("c:"+ p.matcher(c).matches());
返回:a:false b:true c:true
所以,我的问题是,我错过了什么?
谢谢,Linus
[the JSoup discussion page suggested I ask my question here.]
So, I am no regex expert, but I'm wondering about the results I get from the jsoup getElementsByAttributeValueMatching() method.
If I have an html page that has (among others) the following links:
<a href="/tweb/tiles/twr/EIDS_AT_20130108T134335/01/">Parent Directory</a> <a href="1357681618315/">1357681618315/</a> <a href="1357681649996/">1357681649996/</a>
And I query with:
Elements dirs = baseDir.getElementsByAttributeValueMatching("href", Pattern.compile("[0-9]+/"));
hoping to get just the 2 links that have only numbers (and a slash at the end.)
However, I get all 3 links back.
I wrote a quick test program to check java's Pattern Matcher response to that regex with the 3 href strings, and it returns only the two with only numbers as I would expect:
String a = "/tweb/tiles/twr/EIDS_AT_20130108T134335/01/"; String b = "1357681618315/"; String c = "1357681649996/"; Pattern p = Pattern.compile("[0-9]+/"); System.out.println("a:"+ p.matcher(a).matches()); System.out.println("b:"+ p.matcher(b).matches()); System.out.println("c:"+ p.matcher(c).matches());
returns: a:false b:true c:true
So, my question is, what am I missing?
thanks, Linus
原文:https://stackoverflow.com/questions/14324540
最满意答案
$(document).ready(function() { $('#text-area-id').focus(); });
点击这里: http : //jsfiddle.net/jxrS7/
$(document).ready(function() { $('#text-area-id').focus(); });
check here: http://jsfiddle.net/jxrS7/
相关问答
更多-
A for Q1:document.getElementById('recalc')。click(); A为Q2:document.getElementById('save')。click(); A for Q3:你可以在一个表单中有几个提交按钮,但你需要在这些提交按钮(名称/值对)中添加“name”属性,这样服务器端就能知道按下了哪个按钮。 希望这些有帮助 A for Q1: document.getElementById('recalc').click(); A for Q2: document.get ...
-
此功能已添加到DT (> = 0.1.3)。 例子: library(shiny) if (packageVersion('DT') < '0.1.3') devtools::install_github('rstudio/DT') library(DT) shinyApp( ui = fluidPage( fluidRow( h1('Client-side processing'), DT::dataTableOutput('x1'), h1('Server ...
-
通过引用评估对象的相等性,因此当您想要选择它时,需要使用完全相同的对象。 $scope.item = { license_year: $scope.license_year_list[1] }; The equality of the objects are evaluated by reference, so you need use the exactly same object when you want to select it. $scope.item = { license_y ...
-
这是一个潜在的想法,也是我们之前在类似情况下使用过的想法: 因为在单击处理程序之前触发了Page Init事件,所以实际上可以检查Request.Form("__EventTarget") ,如果是行单击,则将新的CheckBoxList添加到适当的容器(页面,选项卡等)。 如果要添加多个控件,则必须确保在页面中的某处跟踪添加的项目,以便每次触发Page Init时都可以自动重新创建它们。 You guys will probably get a kick out of this, but the answ ...
-
将以下属性添加到$scope.gridOptions对象: onRegisterApi: function(gridApi) { $scope.gridApi = gridApi; $scope.gridApi.grid.modifyRows($scope.gridOptions.data); $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]); } 这将设置$scope.gridApi以便您在此功能之外需要 ...
-
I am checkbox
... -
$(document).ready(function() { $('#text-area-id').focus(); }); 点击这里: http : //jsfiddle.net/jxrS7/ $(document).ready(function() { $('#text-area-id').focus(); }); check here: http://jsfiddle.net/jxrS7/
-
您可以尝试使用带有html的文本的th:utext标记。 这是官方文档 - 未转义的文本 Things didn't work out using th:text nor th:utext however what I did was to read the document.html as a text file on java and then placed the text on the textarea. I used some most of the code posted on: http:// ...
-
您可以将函数作为参数传递给加载函数,如果它已完成,它将被执行: $('#textarea1').load("TEST", function() { $('#textarea').load("TEST"); }); 有关详细信息,请查看此处 更新: 如果你只想设置textarea的文本,你可以使用val然后调用change来触发第一个textarea的change事件: $("textarea#textarea1").val('TEST').change(); 然后将同一textarea的change ...
-
我想你可能想要像这样使用.setContent() : if($(this).val() == 'template1'){ tinyMCE.activeEditor.setContent($('div div#template1').text()); } 该文件在这里: http : //www.tinymce.com/wiki.php/API3 : method.tinymce.Editor.setContent I guess you might want to use .setC ...