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

            Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

            Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

            How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page