Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the basic grammars commonly used in regular expressions

Shulou Source: shulou.com Published: 2022-06-02 03:43:41 10月17日 Update

This article mainly introduces what are the basic grammars commonly used in regular expressions, which have a certain reference value. Interested friends can refer to them. I hope you will gain a lot after reading this article.

Java regular expressions provide a rich class library, which greatly simplifies the process. The following is a list of common basic grammars:

* +? ^ $[] () | /\ d\ D\ w\ W {} {n} {njue m}, etc.

Note that it is the "|" or symbol. It can match individual characters and strings. For example, t [aeio] n only matches tan,ten,tin,ton. However, toon does not match, because only a single character can be matched in square brackets, and to match toon, you can use t (a | e | I | o | oo) n to achieve toon.

Regular expressions are a skilled process, and there is nothing too abstract. In fact, learning software (do not like the word "programming") and other industries are the same, one of the hard indicators of programmers is the amount of code. The greater the amount of code, the more familiar (or mastered or proficient) the implementation process. Experience is not learned, just as language cannot be learned. That depends on the accumulation of a quantity. Familiarity makes perfect (the ancients are really good, they already knew this truth), the premise of innovation is to achieve a very skilled degree of something. I would like to share with my friends.

(2) String's support for regular expressions:. Regular (regex) matches regular expressions in parentheses

.split (regex) splits the string into an array of characters. Of course, the return value is a character array.

Replace (old String,new String) replaces the old string with the new one. It is important to note that the original string of the replacement process is unchanged, but a string is re-new.

Such as: String str= "abcde"

String str2=str.replace ("bc", "ff"); / / replace "bc" in str with "ff"

System.out.println (str); / / the output str value at this time is the same as the value at the beginning of initialization

The value of System.out.println (str2) / / str2 becomes the "affde" you want.

.replaceAll (regex,String) is similar to replace.

Thank you for reading this article carefully. I hope the article "what are the basic grammars commonly used in regular expressions" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Characters regularities expressions strings articles procedures commonly used syntax code single that is arrays friends industry learning support proficiency awesome two things Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft Shulou Technology Redmi MySQL