簡體   English   中英

Flex RegExp到Java RegExp

[英]Flex RegExp to Java RegExp

最近我正在尋找幫助在flex中使用RegExp提取URL的一些模式,很少有人幫我完成它。 看到這個我需要在java層再次執行它,我試圖在java中應用相同的regExp模式,但它給了我一個錯誤。

var s:String = "www.something.com@param1={{^User Name^}},{{^,e,^}},param2={{^user id^}}";
var userPattern:RegExp = /(?<=param1=)({{\^)([A-Za-z0-9\^}}{{, ])*(})/;
var userIdPattern:RegExp = /(?<=param2=)({{\^)([A-Za-z0-9\^}}{{, ])*(})/;
s = s.replace(userPattern,'username');
s = s.replace(userIdPattern,'user_id');

這給出了www.something.com @param1 = username,param2 = user_id。

有人可以幫助我在java層中執行此操作,相關正則表達式就足夠了。

這是我在java中嘗試過的,

String url = "http://www.google.com/@param1={{^Case Name^}},param2={{^Case Id^}}";
String urlPattern = "/({{\\^)([A-Za-z0-9_\\^}}{{, ])*(})/";
Pattern paramPattern = Pattern.compile(urlPattern);     
Matcher matcher = paramPattern.matcher(url);       
System.out.println("Matches - "+matcher.matches());
System.out.println("Find - "+matcher.find());

它給出了這個錯誤

線程“main”中的異常java.util.regex.PatternSyntaxException:索引1附近的非法重復/({{\\ ^)([A-Za-z0-9 _ \\ ^}} {{,])*(})/

{是Java正則表達式中的元字符,用於有界重復,例如a{1,2}匹配至少1,最多2'a'。 因為你沒有使用它來重復,你應該逃避每個{\\\\

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM