Java:Replace specific word with other content unchanged2019 Community Moderator ElectionHow do I create a Java string from the contents of a file?How do I generate random integers within a specific range in Java?Regular expression to match a line that doesn't contain a word?How to negate specific word in regex?Is there a way to capture each group if multiple occurrences are matched?Greedy vs. Reluctant vs. Possessive QuantifiersThe usage of Pattern, Matcher, replaceTrouble trying to negate a word in Java regexNeed a way to print out lookahead portion of a regex pattern in java?Replace instead of append in java pattern matching?

Old race car problem/puzzle

Why would a flight no longer considered airworthy be redirected like this?

RegionDifference for Cylinder and Cuboid

Why must traveling waves have the same amplitude to form a standing wave?

How to answer questions about my characters?

Does this AnyDice function accurately calculate the number of ogres you make unconcious with three 4th-level castings of Sleep?

An Accountant Seeks the Help of a Mathematician

Is it normal that my co-workers at a fitness company criticize my food choices?

How to explain that I do not want to visit a country due to personal safety concern?

Rules about breaking the rules. How do I do it well?

Rejected in 4th interview round citing insufficient years of experience

Does splitting a potentially monolithic application into several smaller ones help prevent bugs?

Sword in the Stone story where the sword was held in place by electromagnets

Theorems like the Lovász Local Lemma?

Instead of Universal Basic Income, why not Universal Basic NEEDS?

Does the statement `int val = (++i > ++j) ? ++i : ++j;` invoke undefined behavior?

What are some nice/clever ways to introduce the tonic's dominant seventh chord?

Is it possible that AIC = BIC?

I need to drive a 7/16" nut but am unsure how to use the socket I bought for my screwdriver

Dot in front of file

Russian cases: A few examples, I'm really confused

Bash: What does "masking return values" mean?

Identifying the interval from A♭ to D♯

Happy pi day, everyone!



Java:Replace specific word with other content unchanged



2019 Community Moderator ElectionHow do I create a Java string from the contents of a file?How do I generate random integers within a specific range in Java?Regular expression to match a line that doesn't contain a word?How to negate specific word in regex?Is there a way to capture each group if multiple occurrences are matched?Greedy vs. Reluctant vs. Possessive QuantifiersThe usage of Pattern, Matcher, replaceTrouble trying to negate a word in Java regexNeed a way to print out lookahead portion of a regex pattern in java?Replace instead of append in java pattern matching?










-1















I am new here and would you like to help me?



There may be lines like




389 392 "magnifyingglas" 1 0 4 392 6616 0 8529270
0 |



390 391 "armourstand" 1 0 6 391 6630 0 6800 0 |



391 391 "weaponrack" 1 0 6 390 6631 0 6800 0 |




I want to subtract 20 from the second number.



Like




390 391 "armourstand" 1 0 6 391 6630 0 6800 0 |




To




390 371 "armourstand" 1 0 6 391 6630 0 6800 0 |




But I don't know how to do it.



I may get the second number,then I don't know how to do with it.
There may be same numbers in this line,but I just want to replace the second number.



Thanks a lot.



============================================================================
update



 Pattern p = Pattern.compile("^(\d+)\s+3(9)[0-2]\sS+\s+(1)\s+\d\s+6") ;
Matcher m = p.matcher("6621 391 "weaponrack" 1 0 6 371 6631 0 6800 0 |") ;


I want something like this



m.group(2).replace(7);


But I could find the similar method.



I see some documents say that we can use "$" to get the group reference, and it doesn't explain more.



Well, I read lines from text, and use "^(d+)s+3(7)0-21(s+ds+)6"
to find the matched line.
And then I need to replace the 39[0-2] to be 37[0-2].
It can be done by minus 20 or other ways which I don't care.










share|improve this question
























  • You can add some code and contextualize your doubt for a better understanding from the community

    – tomrlh
    Mar 7 at 12:39











  • You just provide a better context of you are trying to do. I don't know what you are talking about. Do you always have 6 digits in your first number?

    – Ctorres
    Mar 7 at 13:16















-1















I am new here and would you like to help me?



There may be lines like




389 392 "magnifyingglas" 1 0 4 392 6616 0 8529270
0 |



390 391 "armourstand" 1 0 6 391 6630 0 6800 0 |



391 391 "weaponrack" 1 0 6 390 6631 0 6800 0 |




I want to subtract 20 from the second number.



Like




390 391 "armourstand" 1 0 6 391 6630 0 6800 0 |




To




390 371 "armourstand" 1 0 6 391 6630 0 6800 0 |




But I don't know how to do it.



I may get the second number,then I don't know how to do with it.
There may be same numbers in this line,but I just want to replace the second number.



Thanks a lot.



============================================================================
update



 Pattern p = Pattern.compile("^(\d+)\s+3(9)[0-2]\sS+\s+(1)\s+\d\s+6") ;
Matcher m = p.matcher("6621 391 "weaponrack" 1 0 6 371 6631 0 6800 0 |") ;


I want something like this



m.group(2).replace(7);


But I could find the similar method.



I see some documents say that we can use "$" to get the group reference, and it doesn't explain more.



Well, I read lines from text, and use "^(d+)s+3(7)0-21(s+ds+)6"
to find the matched line.
And then I need to replace the 39[0-2] to be 37[0-2].
It can be done by minus 20 or other ways which I don't care.










share|improve this question
























  • You can add some code and contextualize your doubt for a better understanding from the community

    – tomrlh
    Mar 7 at 12:39











  • You just provide a better context of you are trying to do. I don't know what you are talking about. Do you always have 6 digits in your first number?

    – Ctorres
    Mar 7 at 13:16













-1












-1








-1








I am new here and would you like to help me?



There may be lines like




389 392 "magnifyingglas" 1 0 4 392 6616 0 8529270
0 |



390 391 "armourstand" 1 0 6 391 6630 0 6800 0 |



391 391 "weaponrack" 1 0 6 390 6631 0 6800 0 |




I want to subtract 20 from the second number.



Like




390 391 "armourstand" 1 0 6 391 6630 0 6800 0 |




To




390 371 "armourstand" 1 0 6 391 6630 0 6800 0 |




But I don't know how to do it.



I may get the second number,then I don't know how to do with it.
There may be same numbers in this line,but I just want to replace the second number.



Thanks a lot.



============================================================================
update



 Pattern p = Pattern.compile("^(\d+)\s+3(9)[0-2]\sS+\s+(1)\s+\d\s+6") ;
Matcher m = p.matcher("6621 391 "weaponrack" 1 0 6 371 6631 0 6800 0 |") ;


I want something like this



m.group(2).replace(7);


But I could find the similar method.



I see some documents say that we can use "$" to get the group reference, and it doesn't explain more.



Well, I read lines from text, and use "^(d+)s+3(7)0-21(s+ds+)6"
to find the matched line.
And then I need to replace the 39[0-2] to be 37[0-2].
It can be done by minus 20 or other ways which I don't care.










share|improve this question
















I am new here and would you like to help me?



There may be lines like




389 392 "magnifyingglas" 1 0 4 392 6616 0 8529270
0 |



390 391 "armourstand" 1 0 6 391 6630 0 6800 0 |



391 391 "weaponrack" 1 0 6 390 6631 0 6800 0 |




I want to subtract 20 from the second number.



Like




390 391 "armourstand" 1 0 6 391 6630 0 6800 0 |




To




390 371 "armourstand" 1 0 6 391 6630 0 6800 0 |




But I don't know how to do it.



I may get the second number,then I don't know how to do with it.
There may be same numbers in this line,but I just want to replace the second number.



Thanks a lot.



============================================================================
update



 Pattern p = Pattern.compile("^(\d+)\s+3(9)[0-2]\sS+\s+(1)\s+\d\s+6") ;
Matcher m = p.matcher("6621 391 "weaponrack" 1 0 6 371 6631 0 6800 0 |") ;


I want something like this



m.group(2).replace(7);


But I could find the similar method.



I see some documents say that we can use "$" to get the group reference, and it doesn't explain more.



Well, I read lines from text, and use "^(d+)s+3(7)0-21(s+ds+)6"
to find the matched line.
And then I need to replace the 39[0-2] to be 37[0-2].
It can be done by minus 20 or other ways which I don't care.







java regex regex-group






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 5:20







Sharon_Xu

















asked Mar 7 at 12:30









Sharon_XuSharon_Xu

12




12












  • You can add some code and contextualize your doubt for a better understanding from the community

    – tomrlh
    Mar 7 at 12:39











  • You just provide a better context of you are trying to do. I don't know what you are talking about. Do you always have 6 digits in your first number?

    – Ctorres
    Mar 7 at 13:16

















  • You can add some code and contextualize your doubt for a better understanding from the community

    – tomrlh
    Mar 7 at 12:39











  • You just provide a better context of you are trying to do. I don't know what you are talking about. Do you always have 6 digits in your first number?

    – Ctorres
    Mar 7 at 13:16
















You can add some code and contextualize your doubt for a better understanding from the community

– tomrlh
Mar 7 at 12:39





You can add some code and contextualize your doubt for a better understanding from the community

– tomrlh
Mar 7 at 12:39













You just provide a better context of you are trying to do. I don't know what you are talking about. Do you always have 6 digits in your first number?

– Ctorres
Mar 7 at 13:16





You just provide a better context of you are trying to do. I don't know what you are talking about. Do you always have 6 digits in your first number?

– Ctorres
Mar 7 at 13:16












1 Answer
1






active

oldest

votes


















0














Well,@Ctorres gives me an idea now.



When I get the matched line,put it in a char array.



First we skip the array first number,and blank spaces.



Then change the char'9' to be '7'.



But I think it's really complex.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043858%2fjavareplace-specific-word-with-other-content-unchanged%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Well,@Ctorres gives me an idea now.



    When I get the matched line,put it in a char array.



    First we skip the array first number,and blank spaces.



    Then change the char'9' to be '7'.



    But I think it's really complex.






    share|improve this answer



























      0














      Well,@Ctorres gives me an idea now.



      When I get the matched line,put it in a char array.



      First we skip the array first number,and blank spaces.



      Then change the char'9' to be '7'.



      But I think it's really complex.






      share|improve this answer

























        0












        0








        0







        Well,@Ctorres gives me an idea now.



        When I get the matched line,put it in a char array.



        First we skip the array first number,and blank spaces.



        Then change the char'9' to be '7'.



        But I think it's really complex.






        share|improve this answer













        Well,@Ctorres gives me an idea now.



        When I get the matched line,put it in a char array.



        First we skip the array first number,and blank spaces.



        Then change the char'9' to be '7'.



        But I think it's really complex.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 13:39









        Sharon_XuSharon_Xu

        12




        12





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043858%2fjavareplace-specific-word-with-other-content-unchanged%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme