Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How to replace text before specific character?
I need to replace a text before '{' character.
([a-z]+)\s?\{ Text: text { Replaced by: test Result: test
How to get a result like test {?
Thanks in advance.
'test{' + 'text{dsdsads'.split('{')[1];
How about this: /[\w\s]+(?={)/
/[\w\s]+(?={)/
Then you could replace the "text" before the { by doing something like:
{
"test2{test1".replace(/[\w\s]+(?={)/,'demo');
Add a comment
You could use a negated [^ ] match combined with a Positive Lookahead.
[^ ]
'text {'.replace(/[^{]+(?={)/, 'test '); //=> "test {"
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
'test{' + 'text{dsdsads'.split('{')[1];