博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
正则表达式转换
阅读量:4145 次
发布时间:2019-05-25

本文共 914 字,大约阅读时间需要 3 分钟。

/**

 * 将字符串中类似8xxxxxxx转换为8[0-9]{0-7}的形式,而不是8[0-9][0-9][0-9][0-9][0-9][0-9][0-9]这种形式
 * @param strInput
 * @return
 */
    public static String transferRegEx(String strInput)
    {
     String str = strInput;
     //str = str.replaceAll("x.", "[0-9]*");不可这样写8xxxxxxx----->会变成str=8[0-9]*[0-9]*[0-9]*x,应当如下转义 
     str = str.replaceAll("x\\.", "[0-9]\\*");
     int size = strInput.length();
     int indexH = 0;
     int indexT = 0;
     int count = 0;
     boolean bFirst = true;
     
     while (str.indexOf("x")>=0)
     {
   for (int i = 0; i < size; i++)
   {
    if (str.charAt(i) == 'x')
    {
     if (bFirst)
     {
      indexH = i;
      bFirst = false;
     }
     count = count + 1;
     continue;

    }

    else
    {
     if (bFirst == false)
     {
      bFirst = true;
      str = str.substring(0, indexH) + "[0-9]{0-" + count
        + "}" + str.substring(indexH + count);
      str = str.trim();
//      System.out.println("--------------cishidezifuchuan:"
//        + str);
      break;
     }
     continue;
     
    }
   }
   //System.out.println("--------------zuikaojinwhile()de:"+str);
  }
  return str;
    }

转载地址:http://txbti.baihongyu.com/

你可能感兴趣的文章
UnityEvent与C#事件系统性能对比
查看>>
Unity 项目设计与管理(上)(下)
查看>>
在Unity 5中如何控制检视面板上的属性是否显示?
查看>>
物理系统最佳实践
查看>>
详解Unity Profiler内存分析问题
查看>>
玩转Unity资源、对象及序列化(上)(下)
查看>>
Unity UI优化技术与技巧
查看>>
如何优化UGUI的ScrollRect
查看>>
Unity中所有特殊的文件夹
查看>>
c#中的反射
查看>>
Unity官方教程|使用Raycast显示射击轨迹
查看>>
Unity 2D教程 | 骨骼动画:介绍
查看>>
Unity 2D教程 | 骨骼动画:创建动画
查看>>
Unity断言库
查看>>
Unity着色器教程 | 积雪效果
查看>>
手把手教你在Unity中实现小地图
查看>>
Unity 动态加载Animator Event 事件
查看>>
Unity中的时间控制 - 关卡创建
查看>>
Unity中的时间控制 - 时间倒退
查看>>
Unity开发小技巧介绍
查看>>