你好,我是正则表达式的新手
^0* -
g
^ asserts position at start of the string
0* matches the character 0 literally (case sensitive)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Global pattern flags
g modifier: global. All matches (don't return after first match)
for String“3454tdfgffg”它应该返回false,因为没有零
下面的是我的例子
public class RegExTest {
public static void main(String args[]){
String pattern ="^0*";
String instance = "3454tdfgffg";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(instance);
if (m.find()) {
System.out.println("Available");
}else
{
System.out.println("Not available");
}
}
}
但它始终返回true,我在实例变量
中编写的内容你能解决我,我错了吗
答案 0 :(得分:4)
它将永远返回true。
party_tomorrow = CalendarEvent(
starts = datetime.datetime.today() + datetime.timedelta(days = 1),
ends = datetime.datetime.today() + datetime.timedelta(days = 1, hours = 5),
repeat = None,
end_repeat = None,
travel_time = datetime.timedelta(hours = 1),
alert = None,
notes = "This is gonna be a load of fun.",
invitees = None
)
匹配零和无限次之间重复的字符Traceback (most recent call last):
File "/Users/George/Library/FlashlightPlugins/calendarquery.bundle/plugin.py", line 62, in test_CalendarEvent
invitees = None
File "/Users/George/Library/FlashlightPlugins/calendarquery.bundle/plugin.py", line 12, in __init__
for key, value in keyword_arguments:
ValueError: too many values to unpack (expected 2)
。在您的字符串中,此字符缺失,因此这意味着字符0*
重复零次,匹配将按预期返回0
。
如果您需要匹配至少一个零,请使用0