Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:30:05+00:00 2026-05-30T19:30:05+00:00

There is a long string of which the structure is <A>N</C></B> <B >E</B> <B

  • 0

There is a long string of which the structure is <A>N</C></B> <B >E</B> <B >N</B> and repeats many times.
(A,B,C,E,N each represents different string)

eg:
<target="FmRight">200910102</A></TD> <TD Nowrap >alvin</TD> <TD Nowrap >93</TD> <target="FmRight">200910103</A></TD> <TD Nowrap >Tom</TD> <TD Nowrap >85</TD>

I want to retrieve the string between the tag , so I wrote two regular expressions

"target=\"FmRight\">\\d+"

"<TD Nowrap >[^<]*</TD>"

and here is the test code

    Pattern p1 = Pattern.compile("target=\"FmRight\">\\d+");
    Pattern p2 = Pattern.compile("<TD Nowrap >[^<]*</TD>");
    Matcher m = p1.matcher(text);
    int count = 0;
    for (int i = 0; i < 3; i++) {
        if(m.find())
            System.out.println(m.group().split(">")[1]);
        m.usePattern(p2);
        count=0;
        for(int j=0;j<2;j++){
            if(m.find())
                System.out.println(m.group().split(">")[1].split("<")[0]);
        }
        m.usePattern(p1);
        count=1;
    }

In jre,it will run properly,but in android, it won’t .
Because in java usePattern()

This method causes this matcher to lose information about the groups
of the last match that occurred. The matcher’s position in the input
is maintained and its last append position is unaffected.

in android usePattern()

Sets a new pattern for the Matcher. Results of a previous find get lost. The next attempt >to find an occurrence of the Pattern in the string will start at the beginning of the >input.

so,how can I maintain the input position while changing the Pattern in android??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:30:06+00:00Added an answer on May 30, 2026 at 7:30 pm

    You can use the region() method to force the Matcher to start looking from the position where the last find() ended.

    Pattern p1 = Pattern.compile("target=\"FmRight\">\\d+");
    Pattern p2 = Pattern.compile("<TD Nowrap >[^<]*</TD>");
    Matcher m = p1.matcher(text);
    int count = 0;
    int regionStart= 0;                          // <-----
    for (int i = 0; i < 3; i++) {
        if(m.find()) {
            regionStart = m.end();               // <-----
            System.out.println(m.group().split(">")[1]);
        }
        m.usePattern(p2);
        m.region(regionStart, m.regionEnd());    // <-----
        count=0;
        for(int j=0;j<2;j++){
            if(m.find()) {
                regionStart = m.end();           // <-----
                System.out.println(m.group().split(">")[1].split("<")[0]);
            }
        }
        m.usePattern(p1);
        m.region(regionStart, m.regionEnd());    // <-----
        count=1;
    }
    

    EDIT: Correction: you should be able to do this. I don’t speak Android, so I don’t know if they’ve messed this up, too. :-/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to split a long string of HTML after N words?
Long.parseLong(string) throws an error if string is not parsable into long. Is there a
There is a long running habit here where I work that the connection string
Hi, I have 20 strings, each of which will have same package structure except
i've got a long string which is space delimited (read in from a txt
I have a string which could be arbitrary long say s = 'Choose from
I have a data structure which represents a train, which can be made up
char c='c'; int i=10; double d =50; long l=30; String s=Goodbye; Are these statement
I can get simple examples to work fine as long as there's no master
When you have a LPCWSTR, why is it a Long Pointer? There's no Long

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.