#Is anyone good at Regex that can help me with something kinda complex?

31 messages · Page 1 of 1 (latest)

astral egret
#

So I am trying to make something that takes in a string, and you can use custom variables inside the string to define certain things in the string to replace and return it and stuff.

#

My idea is to have a string such as @text("Hello, ")@selector("@a") and I want to find what type is next to the @ and then if it's either "text", "selector", or "score" then I want to find what's inside the ()

#

other string templates:

@text("Welcome, ")@selector("@s")@text(" to Bedrock Add-Ons! We hope you love it here!")
@text("Your current Money is: ")@score("name":"@s","objective":"money")

#

basically: Search string for @ and any valid type (text, score, selector) and then get the value inside the parenthesis () if the type is valid

#

then after that i'd need to get the values for the score stuff but that's for later

bitter musk
astral egret
#

what I need is for it to only detect certain types

#

like text, selector, and score only

astral egret
#

I set it up to do that tho

wooden grotto
#

i can make that

#

if u want

wooden grotto
#

@(\w+)\((\s*"([^"\\]|\\.)*"(\s*[:,])?)+\)

astral egret
#

this is what I use currently

#

gotta figure out how to do a few other things now

wooden grotto
#

my is robust xd

wooden grotto
astral egret
#

I'm just gonna use this and use a for-loop

wooden grotto
#
let array = [...'@text("Welcome, ")@selector("@s\")'.matchAll(regex)]

//array
[
  [ orignal, keyword, argument ],
  [ orignal, keyword, argument ]
]
astral egret
#

this is my input

#

the 3rd argument is the main input it takes

#

the first 2 are temporary

wooden grotto
#

well you dont seem to know regex well use whatever u want but the one i sent is lot more advance than any other

it gets keyword, argument, escaped string, little syntax checking, without hardcore pattern

astral egret
wooden grotto
#

?

astral egret
#

got it

#

custom variables to turn into tellraw elements

arctic kayak
#

I've been tryna do the same thing

#

Except with a different syntax mine was like "Hello hi <@s> my score is <@s>kills>"

astral egret