How do I write a regex to match a specific word?

0
Hi, I want to find a certain word in a string and replace it with 'TEST'. For example: String: Donotgotothemarketwithoutmoney Word: market Output: DonotgototheTESTwithoutmoney Therefore, I would need a regex to search for 'market' in the input string, match it and replace it with 'TEST'. Many thanks and kind regards, Razvan
asked
3 answers
4

If you just want to replace a literal string without worrying about special regex characters you can either

1) use the  Pattern.quote(String s):String method

2) wrap your string literal in 

'\Q' + someLiteral + '\E'

Regards,

Andrej

 

 

answered
2

I think replaceAll('Donotgotothemarketwithoutmoney', 'market', 'TEST') is all you need.

See also https://docs.mendix.com/refguide/string-function-calls

 

answered
1

For testing Regex this site is usefull: https://www.regexone.com/

And there you can also learn on how to use regex.

Regards,

Ronald

 

answered