Skip to content

add a text replace expression#8587

Open
novystar wants to merge 31 commits into
SkriptLang:dev/featurefrom
novystar:feature/replace_expression
Open

add a text replace expression#8587
novystar wants to merge 31 commits into
SkriptLang: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
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
@novystar
Copy link
Copy Markdown
Author

novystar commented May 9, 2026

Hey @sovdeeth I'm still waiting for review/approval on this, thanks

@sovdeeth
Copy link
Copy Markdown
Member

sovdeeth commented May 9, 2026

Hey @sovdeeth I'm still waiting for review/approval on this, thanks

Thanks for the reminder, will review later tonight

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.

Looks great! Nice work

Comment thread src/main/java/org/skriptlang/skript/common/elements/expressions/ExprReplace.java Outdated
@github-project-automation github-project-automation Bot moved this from In Review to Awaiting Merge in 2.16 Releases May 10, 2026
novystar and others added 2 commits May 10, 2026 10:04
…s/ExprReplace.java

Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
@novystar
Copy link
Copy Markdown
Author

While testing my examples i ran into an unhandled exception when using an out of bounds regex group in the replacement e.g. '$99'. I also applied my fix to EffReplace, hope thats okay!

novystar added 4 commits May 10, 2026 12:04
… feature/replace_expression

# Conflicts:
#	src/main/java/ch/njol/skript/effects/EffReplace.java
#	src/main/java/org/skriptlang/skript/common/elements/expressions/ExprReplace.java
@skriptlang-automation skriptlang-automation Bot added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label May 11, 2026
Copy link
Copy Markdown
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

Looks pretty good, just a few things :)

Comment thread src/main/java/ch/njol/skript/effects/EffReplace.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
Comment thread src/main/java/org/skriptlang/skript/common/elements/expressions/ExprReplace.java Outdated
@github-project-automation github-project-automation Bot moved this from Awaiting Merge to In Review in 2.16 Releases May 20, 2026
@skriptlang-automation skriptlang-automation Bot removed the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label May 20, 2026
novystar and others added 2 commits May 20, 2026 16:39
Co-authored-by: Patrick Miller <apickledwalrus@icloud.com>
@novystar novystar requested a review from APickledWalrus May 20, 2026 16:02
@novystar
Copy link
Copy Markdown
Author

hey @APickledWalrus waiting on approval for those changes when you can, thanks 🙏

Copy link
Copy Markdown
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

Just about there! Thanks for your work so far 🙂

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/ch/njol/skript/effects/EffReplace.java
novystar and others added 3 commits May 27, 2026 17:54
@novystar novystar requested a review from APickledWalrus May 27, 2026 17:33
Copy link
Copy Markdown
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

Great work!

@github-project-automation github-project-automation Bot moved this from In Review to Awaiting Merge in 2.16 Releases May 27, 2026
@skriptlang-automation skriptlang-automation Bot added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label May 27, 2026
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. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.

Projects

Status: Awaiting Merge

Development

Successfully merging this pull request may close these issues.

4 participants