The study record of Regular Expression 正则表达式学习笔记

Regular expressions are the key to powerful, exible, and efŒcient text processing. Regular expressions themselves, with a general pattern notation almost like a mini programming language, allow you to describe and parse text. When scratch some web information from Internet, I realize the power of Regular Expressions. From today, I will study the RE step by step.

    Some definations or speacial terms should be given first!

    Metacharacters: Full regular expressions are composed of two types of characters. The special characters (like the "+" "." ) are called metacharacters,while
the rest are called literal, or nor mal text characters

    What sets regular expressions part from Œlename patterns are the advanced expressive powers that their metacharacters provide. Filename patterns provide limited metacharacters for limited needs, but a regular expression ™languageš provides rich and expressive metacharacters for advanced uses.

    Egrep:Finding text is one of the simplest uses of regular expressionsŠmany text editors and word processors allow you to search a document using a regular-expr ession pattern. Even simpler is the utility egrep.

    Figure 1 shows you some metachracters that I have learnt from the book "Mastering Regular Expressions"

 

   

    (1) The metacharacter "." (usually called dot or point) is a shorthand for a character class that matches any character.

    Example:

    if you want to search for a date such as 03/19/76, 03-19-76, or even 03.19.76, you could go to the trouble to construct a regular expression that uses character classes to
explicitly allow `/', `-', or `.' between each number, such as 03[-./]19[-./]76.
However, you might also try simply using 03.19.76

   (2) The regular-expression construct "[ ]", usually called a character class.

   Example:

   "[123456]" matches any of the listed digits.

   (3) "[^]" instead of "[]", the class matches any character that isn't listed.

   Example:

       "[^1-6]" matches a character that's not 1 thr ough 6.

   Continue:::::

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中,String和StringBuffer都是用来存储和操作字符串的类。String是字符串常量,不可更改的常量,而StringBuffer是字符串变量,可以扩充和修改的对象。\[2\] String的使用方法包括字符串的拼接、截取、替换等操作。例如,可以使用"+"运算符来拼接字符串,使用substring()方法来截取字符串的一部分,使用replace()方法来替换字符串中的某个字符或子串。 StringBuffer的使用方法与String类似,但是它的对象是可变的,可以通过append()方法在字符串末尾追加字符或字符串,通过insert()方法在指定位置插入字符或字符串,通过reverse()方法将字符串反转。\[1\] 正则表达式是一种用来匹配和处理字符串的强大工具。在Java中,可以使用java.util.regex包中的类来操作正则表达式。可以使用Pattern类来定义正则表达式的模式,使用Matcher类来进行匹配操作。正则表达式可以用来验证字符串的格式、提取字符串中的特定部分等。在使用正则表达式时,可以使用String类的matches()方法来判断一个字符串是否匹配某个正则表达式。\[3\] #### 引用[.reference_title] - *1* *2* *3* [Java------String类和正则表达式](https://blog.csdn.net/m0_64365419/article/details/127338894)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值