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

  • Home
  • SEARCH
  • 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 3601340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:36:36+00:00 2026-05-18T20:36:36+00:00

the question sounds a bit confusing, but it is actually straightforward. This is a

  • 0

the question sounds a bit confusing, but it is actually straightforward. This is a follow-up of my previous post:

Need a little help on this regular expression

after successful transformation of the String, now the String looks like:

<media id="pc011018" rights="licensed"
        type="photo">
        <title>Sri Lankans harvest tea</title>

Now the only task left is to swap the three attributes of media node, so the output String should be:

<media type="photo" id="pc011018" rights="licensed">
        <title>Sri Lankans harvest tea</title>

I actually could think of a way of doing this: first of all, I extract the string enclosed by the first pair of “[” bracket. Then for this string, I will use a StringTokenizer to tokenize three attributes strings: type, id, rights; then rearrange them in a StringBuffer,turn it back into a string, then finally concatenate with the remaining [title] substring.

I am just wondering if there is a better and more efficient way rather than using StringToknizer? Please kindly help, thanks.

  • 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-18T20:36:37+00:00Added an answer on May 18, 2026 at 8:36 pm

    A real hacky way of doing this

        String input="<media id=\"pc011018\" rights=\"licensed\" type=\"photo\"><title>Sri Lankans harvest tea</title></media>";
        Pattern r= Pattern.compile("<media id=\"(.*)\" rights=\"(.*)\" type=\"(.*)\">(.*)");
        Matcher m = r.matcher(input);
        m.find();
        System.out.println("<media type=\""+m.group(3)+ "\" + id=\""+ m.group(1) + "\" rights=\"" + m.group(2) + "\">"+m.group(4));
    

    Will only work if the data is always as you describe

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

Sidebar

Related Questions

This might sound like a little bit of a crazy question, but how can
Sounds like a weird question, but say I have something like this: $.post( /myajax.php,
Sorry if this sounds like a really stupid question, but I need to make
This sounds like a look-up-in-the-manual question to me, but I can't find it. Suppose
I know this sounds like a really obvious question, but it's proving harder to
I'm sure this sounds like a n00b question, but how do I add sub
I know this question might sound a little cheesy but this is the first
This might sound like a stupid question, but google didn't help me. Is there
I know the question sounds silly, but consider this: I have an array of
This question may sound fairly elementary, but this is a debate I had with

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.