“仅字符串拆分”;UTC−;11:00“;使用regexjava从时区
我只想拆分“UTC”−11:00“从时区使用正则表达式java。 我的琴弦“仅字符串拆分”;UTC−;11:00“;使用regexjava从时区,java,javascript,regex,string,timezone,Java,Javascript,Regex,String,Timezone,我只想拆分“UTC”−11:00“从时区使用正则表达式java。 我的琴弦 United States - UTC−12:00 : Baker Island and Howland Island United States - UTC−11:00 : American Samoa, Jarvis Island, Kingman Reef, Midway Atoll and Palmyra Atoll 我想用这种方法工作。此方法只能返回“UTC-12:00” 你能帮忙吗 public nativ
United States - UTC−12:00 : Baker Island and Howland Island
United States - UTC−11:00 : American Samoa, Jarvis Island, Kingman Reef, Midway Atoll and Palmyra Atoll
我想用这种方法工作。此方法只能返回“UTC-12:00”
你能帮忙吗
public native String jsRegExp(String str, String regex)
/*-{
return str.replace(/regex/, ''); // an example replace using regexp
}-*/;
您可以使用
String
类的replaceAll()
函数将其替换为新形状,而不是使用Pattern
拾取匹配的组
String str = "United States - UTC-12:00 : Baker Island and Howland Island";
System.out.println(str.replaceAll(".*?-\\s+|(?<=\\d\\d:\\d\\d)\\s+:.*", ""));
解析时出现错误。错误为:无效quantifier@npprasanth对于哪个输入或正则表达式?在运行应用程序时准确获取此信息。。。columnNumber:2:无效的量词。但主要是在工作method@npprasanth请用您正在尝试的代码更新您的问题!我已经编辑了我的问题。顺便说一下,在javascript中使用正则表达式并没有得到确切的值
var str = "United States - UTC-12:00 : Baker Island and Howland Island";
str = str.replace(/.*?-\s+|(\d\d:\d\d)\s+:.*/g, "$1");