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?
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
add a comment |
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
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
add a comment |
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
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
java regex regex-group
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 7 at 13:39
Sharon_XuSharon_Xu
12
12
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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