sending and receiving addresses are fixed and can be written to death directly, but the sessionId is changed, you need to extract it from the feedback data first, I am using a simple regular expression:
String strResult = EntityUtils. toString (httpResponse. getEntity ());
Pattern p = Pattern. compile ("sessionId =. (\ d +)"); // get sessionId
Matcher m = p. matcher (strResult );
If (m. find () mSessionId
Package Test;import java.util.regex.matcher;import java.util.regex.pattern;/** mailbox: @ Front contains 5-14 digits, letter underline, @ behind is QQ, 126,163,yahoo,gmail,sina, then COM or CN. * Phone Number: 11 digits, the first two digits are 13,15,16,17,18,19* identity card 18 bits: 5 Start, 7th, 8 digits 19 or 20, 11th digit 0 or 1, 13th digit 0 or 1 or 2 or 3, 18th bit may be x* domain name: www, then a ".", followed by a number or letter or underscore (unlimited length), followed by ".",
LookThe final result of the surround look match is a location with four types of surround look:The (? =expression) order is sure to look around, indicating that the right side of the position matches Expression(?! expression) , which indicates that the right side of the position does not match the expression(? in reverse order, which indicates that the left side of the position matches the Expression(? reverse the negative look, indicating that the left side of the position does not match expr
Regular expressions are used in the general way:Pattern: The compiled representation of the regular expression. That is, each pattern object represents a rule! There is no construction method, and the following method is used to return the Pettern object public static pattern compile (String regex) to compile the given regular expression into the pattern. Creates a corresponding pattern object by the given string form public Matcher
Example 1For news content or blog articles, if the abstract is displayed, you need to remove the html format tag of the content, find a regular expression, and implement: The code is as follows:Copy code /*** Delete the html format in the input string * * @ Param input* @ Param length* @ Return*/Public static String splitAndFilterString (String input ){If (input = null | input. trim (). equals ("")){Return ""; } // Remove all html elements,String str = input. replaceAll (
+ "," $1 "); STR = Str. replaceall (Reg, newstr); system. out. println (STR );}
4. Obtain: remove the sub-strings that match the rules in the string.
Procedure:1. encapsulate a regular expression into an object.2. Associate the regular object with the string to be operated.3. Obtain the regular expression matching engine after Association.4. Use the engine to perform operations on the sub-strings that comply with the rules, such as extracting them.
Import Java. util. regEx. *; Class regexd
-length ).Endloop.
* Find the phone number in the ***-********* format in the string.STR = 'ip1: 172.16.32.12 021-12345678 '.Find all occurrences of RegEx '/d {3}-/d {8} |/d {4}-/d {7}' in STR results result_tab.Write /'-----'.Loop at result_tab into WA.Write/STR + wa-offset (wa-length ).Endloop.
* Find the 15/18-digit ID number in the string.STR = 'ip1: 172.16.32.12 3722198003041234 '.Find all occurrences of RegEx '/d {15} |/d {18}' in STR results result_tab.Write /'-----'.Loop at result_tab in
Java parses HTML Tag, java parses tag
Import java. util. hashMap; import java. util. map; public class TagParser {private Integer index = 0; private char [] tagChar; private int position = 0;/* parse symbol */private char symbol = '"'; public static final String START_SCRIPT = "
How does java parse html tags?
If it is too troublesome, there is a jar package dedicated to parsing html. The free jar package is called jsoup. You can search for any tag on a page and obtain no more than four codes.JA
Regular Expression
Re-pattern function:
The function (re-pattern) accepts a string parameter and returns a regular expression style (java. util. regex. Pattern class instance ). This style can be used for regular expression matching.
You can also use a macro to directly input a regular expression in text format: Use the # symbol before the string. The expression is the same as that generated using the re-pattern function. For example, the following representation is the same as that in the p
common methods for DOM query.
// Switch to the shouldUseXPath method supported by FF below !!!
Copy codeThe Code is as follows: // when you determine whether to use XPath for query, the compileXPathMatcher method is called.
CompileXPathMatcher: function (){// Provide the patterns and xpath belowVar e = this. expression, ps = Selector. patterns,X = Selector. xpath, le, m, len = ps. length, name;
// Determine whether the query string e is cachedIf (Selector. _ cache [e]) {This. xpath = Selector.
Statement
You are welcome to repost, but please keep the original source of the article :)Blog: http://www.cnblogs.com
Farmer's uncle: http://over140.cnblogs.com
Body
1. obtain all the activities under the ApplicationPublic static ArrayList ArrayList Intent intent = new Intent (Intent. ACTION_MAIN, null );
Intent. setPackage (ctx. getPackageName ());
For (ResolveInfo info: ctx. getPackageManager (). queryIntentActivities (intent, 0 )){
Result. add (info. activityInfo. name );
}
Return result;
}
:
// Person performs operations on the entire table
// Person/id
Private DBOpenHelper dbOpenHelper;
Private static final UriMatcher MATCHER = new UriMatcher (UriMatcher. NO_MATCH); // new UriMatcher (code); code indicates the value returned when the matching fails;
Private static final int PERSONS = 1;
Private static final int PERSON = 2;
// Set matching items
Static {
MATCHER. addURI ("cn. wordtech. provid
companies including Yanzhou Coal Mining Co, "+" Youku Tudou Inc and cosmetic e-commerce Jumei International Holding jumped by more than 10 percent on "+" Wednesday, compared to a 0.15 percent advance in the Dow Jones Industrial Average. ";/*** find the string position * in the format of" XXing "(note that" ing "is followed by a string, which is not followed by a string) */private void findIndex () {String input = "\ Bing \ B"; Pattern p = Pattern. compile (input);
The Java Regular expression string pattern.Regular expressions can be used to search, edit, and manipulate text.Regular expressions are not limited to one language, but are subtle in each language.There are 3 main classes in the Java.util.regex package:
Pattern class:The pattern object is a compiled representation of a regular expression. The pattern class has no public constructor method. To create a pattern object, you must first call its public static compilation method, which return
Just having a requirement to extract all the specific characters in a string is tedious if you are dealing with a regular string. So I thought of using regular expressions to do it. Project requirements are: need to extract the last number of license plate number, such as: Su A7865 extract 5, su a876x extract 6
Implementation method:
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;
public class Test {public
static void Main (string[] args) {
String s = ' a876x ';
Write t
Brief introduction:
Java.util.regex is a class library package that uses patterns that are customized by regular expressions to match strings.
It consists of two classes: pattern and Matcher
Pattern
A pattern is a compiled representation of a regular expression.
Matcher
A Matcher object is a state machine that expands the match
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.