Skip to content

add a text replace expression#8587

Open
novystar wants to merge 18 commits intoSkriptLang:dev/featurefrom
novystar:feature/replace_expression
Open

add a text replace expression#8587
novystar wants to merge 18 commits intoSkriptLang:dev/featurefrom
novystar:feature/replace_expression

Conversation

@novystar
Copy link
Copy Markdown

Problem

In skript, there is currently only an effect for text replacement, meaning you have to store the value somewhere before doing the replacement which can be inconvenient and takes up more lines.

Solution

This PR adds a replace expression, meaning you can now do in 1 line what used to take 3.

Before:

set {_message} to "Hello [player]"
replace "[player]" in {_message} with {_playerName}
send {_message} to {_player}

After:

send replace "[player]" in "Hello [player]" with {_playerName} to {_player}

Syntaxes (same as the effect):

"replace [(all|every)|first:[the] first] %strings% in %strings% with %string% [case:with case sensitivity]"
"replace [(all|every)|first:[the] first] %strings% with %string% in %strings% [case:with case sensitivity]"
"(replace [with|using] regex|regex replace) %strings% in %strings% with %string%"
"(replace [with|using] regex|regex replace) %strings% with %string% in %strings%"

Testing Completed

src/test/skript/tests/syntaxes/expressions/ExprReplace.sk

Supporting Information

The current syntax being the same as the effect may be a little unintuitive.

I also encountered a ParserInstance related Skript API Exception while trying to add null test cases to my unit test. I am assuming its a bug with the test effect since it behaves as normal in effect commands and scripts.


Completes: none
Related: none
AI assistance: none

@novystar novystar requested a review from a team as a code owner April 23, 2026 19:28
@novystar novystar requested review from Burbulinis and TheMug06 and removed request for a team April 23, 2026 19:28
@skriptlang-automation skriptlang-automation Bot added needs reviews A PR that needs additional reviews needs triage An issue that hasn't been classified or verified yet labels Apr 23, 2026
@skriptlang-automation

This comment has been minimized.

Comment thread src/main/java/ch/njol/skript/expressions/ExprReplace.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprReplace.java
Comment thread src/main/java/ch/njol/skript/expressions/ExprReplace.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprReplace.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprReplace.java Outdated
@skriptlang-automation skriptlang-automation Bot added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label Apr 23, 2026
@skriptlang-automation skriptlang-automation Bot removed the needs triage An issue that hasn't been classified or verified yet label Apr 23, 2026
@github-project-automation github-project-automation Bot moved this to In Review in 2.16 Releases Apr 23, 2026
Copy link
Copy Markdown
Member

@Efnilite Efnilite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there 🙏

Comment thread src/main/java/org/skriptlang/skript/common/elements/expressions/ExprReplace.java Outdated
Comment thread src/main/java/org/skriptlang/skript/common/elements/expressions/ExprReplace.java Outdated
Comment thread src/main/java/org/skriptlang/skript/common/elements/expressions/ExprReplace.java Outdated
Comment thread src/main/java/org/skriptlang/skript/common/elements/expressions/ExprReplace.java Outdated
@skriptlang-automation skriptlang-automation Bot removed the needs reviews A PR that needs additional reviews label Apr 25, 2026
novystar and others added 2 commits April 25, 2026 15:05
Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
Copy link
Copy Markdown
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good

Comment thread src/main/java/org/skriptlang/skript/common/elements/expressions/ExprReplace.java Outdated
Comment thread src/main/java/org/skriptlang/skript/common/elements/expressions/ExprReplace.java Outdated
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
@Efnilite Efnilite requested a review from sovdeeth April 28, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Feature request, an issue about something that could be improved, or a PR improving something.

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

4 participants