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

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

阅读 4k
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@

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏