I will not sell it to anyone here. in fact, almost all JavaScript regular expressions can be judged in Java. Of course, here we talk about written statements (not special ). it's just a double slash processing, and some class judgments are added. Java is a little more complicated than JavaScript. is to use the reference classes and methods in practice. well, let's talk about some of your small applications. here is an example of determining the IP address in practice.
There are quite a few regular expressions in Javascript writing. Since I made a small jxl Excel import control yesterday, I didn't consider its format judgment at the time, so I began to refine it today, maybe you are very familiar with some JavaScript regular expressions, and may be confused for several seconds when you go to Java. the same is true for me. I just switched to Java to determine whether the IP address is valid. at this time, I am sleepy. Because this is the first time I write Java regular expressions, I used to make a general judgment. I checked it online and added my own thoughts. (normal people's thinking. it turns out that a little bit of content can be used to solve the problem.
- Import java. util. RegEx .*;
- // Specific classes. You can check the API or its source file by yourself. I will not talk about it here. I am also a dish.
- // One bird
Well, with the package here, the others are actually used. First, we will provide a very simple method we have written. It is quite simple.
- // Test whether the IP address is valid
- Public Boolean isip (string IPaddress ){
- String test = "([1-9] | [1-9] // d | 1 // d {2} | 2 [0-1] // d | 22 [0-3]) (//. (// d | [1-9] // d | 1 // d {2} | 2 [0-4] // d | 25 [0-5]) {3 }";
- Pattern pattern = pattern. Compile (test );
- Matcher = pattern. matcher (IPaddress );
- Return matcher. Matches ();
- }
In a simple method, the test is actually written in Javascript, but a slash "/" is added when it is taken, which is so simple. Here is simply to say, in fact, it is not that complicated to use. I have found a lot on the Internet, but it is not satisfactory. Why? It is actually my own reason, because when I came into contact with new things, I always think there is something missing. in fact, this thing enables you to implement your functions and meet your requirements. However, it takes a while for you to use it. This is a process.
Well, here we are. I hope you can solve your problems and be brave enough to solve your own problems.