Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use regular expressions in Java

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to use regular expressions in Java". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn "how to use regular expressions in Java".

Overview

A regular expression is a logical formula for manipulating strings (including ordinary characters (for example, letters between an and z) and special characters (called "metacharacters"). It is to use predefined specific characters and a combination of these specific characters to form a "regular string", which is used to express a filtering logic for a string. A regular expression is a text pattern that describes one or more strings to match when searching for text.

Recognize regular expression syntax

In other languages,\\ means: I want to insert a normal (literal) backslash into a regular expression, please don't give it any special meaning.

In Java,\\ means: I'm going to insert a backslash of a regular expression, so the characters that follow have a special meaning.

So, in other languages (such as Perl), one backslash\ is sufficient for escaping, while in Java regular expressions require two backslashes to be parsed to escape in other languages. It is also easy to understand that in Java's regular expression, two\\ represent one of the other languages, which is why the regular expression that represents a digit is\ d, while the normal backslash is\.

Character description\ marks the next character as a special character, text, backreference, or octal escape character. For example, "n" matches the character "n". "\ n" matches the newline character. The sequence "\" matches "," ("match" ("match"). ^ matches the position where the input string begins. If the Multiline property of the RegExp object is set, ^ also matches the position after "\ n" or "\ r". $matches the position at the end of the input string. If the Multiline property of the RegExp object is set, $also matches the position before "\ n" or "\ r". * match the previous character or subexpression zero or more times. For example, zo* matches "z" and "zoo". * equivalent to {0,}. + matches the previous character or subexpression one or more times. For example, "zo+" matches "zo" and "zoo" but not "z". + is equivalent to {1,}. ? Matches the previous character or subexpression zero or once. For example, "do (es)?" Matches the do in "do" or "does". ? It is equivalent to {0jue 1}. {n} n is a non-negative integer. It happens to match n times. For example, "o {2}" does not match "o" in "Bob", but matches two "o" in "food". {n,} n is a non-negative integer. Match at least n times. For example, "o {2,}" does not match "o" in "Bob", but matches all o in "foooood". "o {1,}" is equivalent to "o +". "o {0,}" is equivalent to "o *". {n ·m} m} m and n are nonnegative integers, where n

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report