正则表达式如何取出被@包裹的字符串?

select * , @ as iid from as_person where icorp = @icorp@ and iperosn = @iperson@
如何通过正则表达式取出被@包裹的数据,取出icorp,iperson?

阅读 4.2k
2 个回答
String express = "@(\\w+)@";
        String sqlString = "select * , @ as iid from as_person where icorp = @icorp@ and iperosn = @iperson@";
        Matcher match = Pattern.compile(express).matcher(sqlString);
        while (match.find()) {
            System.out.println(match.group(1));
        }
        String express = "(\\@\\w+\\@)";
        String sqlString = "select * , @ as iid from as_person where icorp = @icorp@ and iperosn = @iperson@";
        Matcher match = Pattern.compile(express).matcher(sqlString);
        while (match.find()) {
            System.out.println(match.group());
        }

结果是
@icorp@
@iperson@

推荐问题