Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
deodexed5736y@AlexDeLarge I guess he means a regex that finds what matches the expression and replace it by something else
-
@AlexDeLarge
@deodexed
Basically, if I've got the string 'foo foo bar', I want to do something like replace('foo foo bar', [[/foo/g, 'bar'], [/bar/g, 'foo' ] and it should return 'bar bar foo' -
perotti7876yYou'd have to evaluate all the occurrences of n conditions.
I can see why you'd want to use it.
Are you elaborating a proposal to a language of some sort of are you thinking about how to implement it?
If the latter, I'd build a parser myself.
Still, how you'd deal with conflicts between two different expressions?@ScriptCoded -
@perotti I'm going to implement it in JS a some sort of function. The best solution I think would be to have whatever search matches first take precedence. Thing is, if the replacer is 'bar($1)', I think I'd like other matches to match the value of $1. Problem is that this is getting into some deep recursion, and I want it lightweight 😅
-
perotti7876y@ScriptCoded the problem with that logic is that your example would give us 'foo foo foo' in the end
-
@perotti Would it?
/foo/g would match *foo foo* bar
/bar/g would match foo foo *bar*
So there are not conflicts
What I'm proposing is that if two matches overlap, say /foo/ and /o f/, then the first one would take precedence. -
perotti7876y@ScriptCoded if you are using tokens to represent change and expect no conflicts, ya. Else, something must take precedence
Related Rants
How would you go about doing a simultaneous regex replace in JS ES6?
question
javascript
regex