Python的正则表达式几小时到几分钟(Python regex hours to minutes)
我有几个小时写的字符串,我想转换为分钟
一些示例输入字符串:
50 hour 5 hrs 3 hours 5hrs 1hour
我试图找出一些正则表达式来捕获所有这些,并将整个事件转换为一个整数,即分钟值
以上将变成:
3000 300 180 300 60
我不太熟悉正则表达式。 我开始玩这样的东西:
re.sub(r'^\d+[a-z]', 'blah', string)
然而,这似乎并没有吸引太多。 只有一个数字后跟一个字母的情况。 此外,我不确定如何实际将转换转换为分钟
I have a bunch of strings written in hours that I want converted to minutes
Some example input strings:
50 hour 5 hrs 3 hours 5hrs 1hour
I'm trying to come up some regex that will capture all of them and convert the whole thing to an integer that the minute value
The above will turn into:
3000 300 180 300 60
I'm not too familiar with regex. I started playing around with something like this:
re.sub(r'^\d+[a-z]', 'blah', string)
However that doesn't appear to catch much at all. Only situations where theres a single digit followed by a letter. Furthermore, I'm not sure how to actually do the conversion into minutes
原文:https://stackoverflow.com/questions/34305492
最满意答案
使用一个类而不是一个id:
.hide-row { display:none; }
并在您的HTML / PHP文件中:
<table> <tr> <th>Name</th> <th>Address</th> </tr> <?php foreach( $cops as $row ) { ?> <tr class="hide-row"> <td><?php echo $row->name; ?></td> <td><?php echo $row->address; ?></td> </tr> <?php } ?> </table>
如果你必须将你的行分组,你可以使用
tbody
标签而不是div
标签。.hide-row tr { display:none; }
并在您的HTML / PHP文件中:
<table> <tr> <th>Name</th> <th>Address</th> </tr> <tbody class="hide-row"> <?php foreach( $cops as $row ) { ?> <tr> <td><?php echo $row->name; ?></td> <td><?php echo $row->address; ?></td> </tr> <?php } ?> </tbody> </table>
Use a class instead of an id:
.hide-row { display:none; }
And in your html/php file:
<table> <tr> <th>Name</th> <th>Address</th> </tr> <?php foreach( $cops as $row ) { ?> <tr class="hide-row"> <td><?php echo $row->name; ?></td> <td><?php echo $row->address; ?></td> </tr> <?php } ?> </table>
If you have to group your rows you could use a
tbody
tag instead of adiv
tag.Can we have multiple <tbody> in same <table>?
.hide-row tr { display:none; }
And in your html/php file:
<table> <tr> <th>Name</th> <th>Address</th> </tr> <tbody class="hide-row"> <?php foreach( $cops as $row ) { ?> <tr> <td><?php echo $row->name; ?></td> <td><?php echo $row->address; ?></td> </tr> <?php } ?> </tbody> </table>
相关问答
更多-
以角度Js隐藏表格行(Hide table rows in angular Js)[2023-02-24]
我觉得这样的事情应该有效。 基本上,单击按钮将在显示全部或仅显示标记为“未收到数据”的项目之间切换。{{data.UniqueId}} {{data.Name}} CSS溢出表行定位(CSS overflow table row positioning)[2023-08-14]
其中superHappyFunDiv是容器DIV的ID,行是基于0的行索引: function scrollTo(row) { var container = document.getElementById("superHappyFunDiv"); var rows = container.getElementsByTagName("tr"); row = Math.min(Math.max(row, 0), rows.length-1); container.scrollTop ...在css中显示和隐藏div行(show and hide div row in css)[2021-09-29]
然后当您将鼠标悬停在表格中时 ,将出现第二行 那么为什么不这样做: #table:hover .row:last-child { display:table-row; } 另外我建议只使用表格标签 。 它不会带来额外的麻烦,并提供更好的监督。 的jsfiddle 带有表标签的示例 then when you hover the mouse in the table the second row will appear So why not do that: #table:hover .row:la ...这适用于任何代码。 通过使用类和预先存在的数据代码标记,您可以概括禁用和启用行,如下所示。 $('select').selectpicker(); $('.selectpicker').on('change', function(){ var list = []; $('.selectpicker :selected').each(function(i, selected){ list[i] = $(selected).text(); }); $('.item' ...您的问题是您正在使用if语句。 if语句的工作方式是它触发一次,就是这样。 您正在寻找的功能是change() 。 所以它应该是: $(document).ready(function(){ $("#observation_discussed_with_employee").change(function(){ if($("#observation_discussed_with_employee").is('checked'){ $(".hidden_opti ...我会使用这个CSS规则: #HMP_options table tr:nth-child(-2n + 4) { display: none; } http://jsfiddle.net/ZXjWV/ 既然这是IE9 +,你可能想让jQuery帮助它。 在这个例子中,我假设你只想隐藏第2和第4行。 如果你想隐藏6,8等等,你应该使用:nth-child(2n)规则。 I would use this CSS rule: #HMP_options table tr:nth-child(-2n + 4) ...使用CSS隐藏表格行(Hide Table Row Using CSS)[2024-04-06]
使用一个类而不是一个id: .hide-row { display:none; } 并在您的HTML / PHP文件中:Name Address