- 浏览: 748297 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (419)
- 杂软粉墨 (2)
- 创意灵感 (3)
- 经验记录 (137)
- 开源轨迹 (2)
- sip-communicator (2)
- 闲侃杂谈 (8)
- 问题交流 (24)
- 概念模式 (32)
- 难点备案 (5)
- JwChat (1)
- 中国象棋 (1)
- 教育探索 (6)
- 英语研究 (58)
- 星际争霸 (1)
- 电信知识 (1)
- 软件架构 (3)
- 哲学探索 (26)
- 算法灵魂 (8)
- 近视探索 (6)
- 数学数学 (3)
- 牛角钻尖 (23)
- 至强文言 (3)
- 数据结构 (1)
- 宇宙物理 (2)
- 网络架构 (3)
- 游戏领域 (4)
- 图形处理 (2)
- 修炼之路 (8)
- 读书天地 (20)
- 编解乱码 (2)
- 概念探索 (8)
- 格物致知 (1)
- 其它语言 (1)
- 测试领域 (3)
- 文化风流 (1)
- JQuery (1)
- 網頁領域 (1)
- Unix/Linux (1)
- Inside JVM (1)
- 异常分析 (1)
最新评论
-
suyujie:
引用
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
iamzhoug37:
您能说一下"局部变量不受文本顺序限制" 是 ...
声明前为什么能赋值却不能输出,都是使用
from: http://blog.peterdelahunty.com/2008/08/using-back-references-with-string.html
This is small problem i was facing the other day and couldn't find much
information about it on the web so thought i would blog about it.
The problem is how to use back references in Java regular expressions.
The problem is this. Say i have a String like so
"orderM
8orderA
3orderX
2NoReturn
"
and i want to turn it into a String like so:
"order M#8 order A#3 orderX
#2 NoReturn
"
i can do this:
String test = "orderM 8orderA 3orderX 2NoReturn ";
String replaced = test.replaceAll ("([A-Z])([0-9])", " $1#$2 ");
What happens here is:
- first create two regular expression for matching all capital letters [A-Z] and all single digits [0-9]
- Next i then put each of these in a group. using ( ) brackets. The grouping means that the match is remembered and can be referenced by the replace string.
- In the replace string i can then reference the matches via the $n notation where n = the number of the group.
So what happens is: The regular expression processor moves along the string looking for cases of a capital letter next to a digit
. When it find them it stores the capital
letter in a group 1 and the digit
in group 2.
So i want to replace the original match with another string i can.
Also note. The whole expression is automatically added to an implicit group zero 0 that is a group of the whole expression.
String replaced = test.replaceAll ("([A-Z])([0-9])", " '$0' ");
will give
order 'M8' order 'A3' order 'X2' NoReturn
IMPORTANT NOTE:
The
javadoc says that you reference back references with '\n' (were n =
number) but that is not true. That does not work you need to use '$n'.
The javadoc is wrong and needs to be updated.
Pattern javadoc
Hope this helps :)
附上将串中a后一字母大写的正则:
String input = "abcadafghat"; String regex = "a(\\w)"; Matcher m = Pattern.compile(regex).matcher(input); while (m.find()) { String temp = m.group(); String uppercase; uppercase = temp.replaceAll("a(\\w)", "$1").toUpperCase(); input = input.replace(temp, "a" + uppercase); } System.out.println(input);
发表评论
-
关于方法访问控制符protected
2012-11-29 10:38 1268http://bbs.csdn.net/topics/3902 ... -
一个基本问题关于引用的
2012-05-15 10:20 1130问: int a = 1; Integer b = new ... -
我對面向對象和過程的理解。
2012-05-02 08:30 1068我的一些理解。 面向过程,是对客观现象的描述,感觉是有一个上 ... -
stack and heap
2012-01-13 23:17 1054我觉得是根据应用方式 和本身特性 才将内存分区的,目的是提 ... -
program experience conclusion
2011-07-11 15:35 10681. check parameters for validit ... -
PreparedStatement's possible designated parameter
2011-04-29 13:45 991though it's nearly impossible t ... -
clean Log4j
2011-04-12 11:19 1069import org.apache.log4j.BasicCo ... -
about abstract class
2011-04-02 10:34 871yes, we do know abstract class ... -
cvs operations on linux
2011-03-25 09:40 1016http://www.linuxhowtos.org/Syst ... -
regex to exchange two parts
2011-03-24 17:09 1096public class Test { public ... -
About the database locking
2011-03-09 11:02 967http://en.wikipedia.org/wiki/Lo ... -
how to send soap message in java
2011-03-08 10:29 1898import java.io.BufferedReader; ... -
About ShutDownDemo
2011-03-07 15:02 985public class ShutdownDemo { p ... -
How do you know if an explicit object casting is needed
2011-02-24 16:33 1192通俗来讲,不可能将一只是猫的动物强转为狗 再说Graphic ... -
有关MimeUtility
2011-02-24 13:11 3368import java.io.UnsupportedEncod ... -
C#连接sql server 2008的一件2事
2011-02-24 09:01 2157once upon a time, i came upon o ... -
Shadowing, Overriding, Hiding and Obscuring
2011-02-22 15:15 1168当子类属性与父类属性重叠时 这种叫法上是shadowi ... -
JAXP usage
2011-02-16 16:07 1104import java.io.ByteArrayInputSt ... -
运行一个类,如果classpath中路径带空格就加双引号
2011-02-11 11:25 2810注意是这样加: java -cp .;"d:\my ... -
关于ClassPath中的current directory
2011-01-28 16:40 1156Given: 1. package com.company. ...
相关推荐
本文将基于“Using External References in Algorithms Compliant with the TMS320 algorithm standard.pdf”这一应用报告,深入探讨如何在遵循TMS320 DSP算法标准的算法中引用外部实现的功能。 ### 引言:外部功能...
Spring Data MongoDB- Messaging, emailing and caching support- Spring Web MVC- Developing RESTful web services using Spring Web MVC- Functional programming using lambdas and method references-...
After an overview of preliminary concepts, this text introduces stacks and queues using arrays along with a discussion of array-based lists. This is followed by an introduction to linked lists and the...
4.3 Training with Back Propagation 4.3.1 Back Propagation in C++ 4.4 A Primitive Example 4.5 Training Strategies and Avoiding Local Minima 4.6 Variations on Gradient Descent 4.6.1 Block ...
The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object. addHeader(String, String) - Method in interface javax.servlet....
references/detection/engine.py , references/detection/utils.py 和 references/ detection/transforms.py
is quoted with permission, and sources are indicated. A wide variety of references are listed. Reasonable efforts have been made to publish reliable data and information, but the author and the ...
The isalpha() String Method x The isupper() and islower() String Methods x Cryptanalysis x Brute Force x Chapter 10 - Reversi x How to Play Reversi x Source Code x The bool() Function x The random...
Olivier Verdier began using Python for scientific computing back in 2007 and received a PhD in mathematics from Lund University in 2009. He has held post-doctoral positions in Cologne, Trondheim, ...
hibernate4.3.5references chm文档
- **Delegates**: Delegates are references to methods with a particular parameter list and return type. They are used for event handling. - **Events**: Events allow objects to notify other objects of ...
You can use this to redirect all references to TextureA (using TextureA) to TextureB, the same applied for shader, materials, mesh... Beware that replace references is very powerful yet dangerous ...
Feature 1 - Project Cleaner: 1、Actions for unused files 2、Enhanced Project View Feature 2 - Find References: 1、Find references, usages, relationships easily in ...2、Explore usages & references
《Python库 wagtail_references-0.0.2详解》 在Python编程领域,库的使用是提高开发效率和代码质量的重要手段。今天我们要探讨的是一个名为`wagtail_references`的Python库,版本号为0.0.2,它封装了一些特定的功能...
Using the Code from This Book Audience Organization Further Reading Conventions Used in This Book How to Contact Us Safari® Enabled Acknowledgments Chapter 1. Text Introduction ...
《torch.vision.references.detection深度解析》 在Python的机器学习领域,PyTorch是一个备受推崇的框架,它以其灵活性和高效性深受开发者喜爱。在PyTorch的生态系统中,torch.vision模块提供了图像处理和计算机...
Graphics and GUIs with matlab, third edition CONTENTS 1 INTRODUCTION 1.1 OVERVIEW 1.2 ORGANIZATION OF THIS BOOK 1.3 TERMINOLOGY AND THE MATLAB PROGRAMMING LANGUAGE 1.3.1 Getting Started 1.3.2 Getting ...